LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   passwords in shell scripts (https://www.linuxquestions.org/questions/linux-software-2/passwords-in-shell-scripts-369511/)

djcham 10-03-2005 06:55 PM

passwords in shell scripts
 
hello!

i'm trying to write a script that will run a bunch of tests for me by transferring files using SCP.

I would like to write a script that will SCP, then enter my password and repeat. How do i write a code that wil wait for a prompt and then enter a password? Thanks a lot!

homey 10-03-2005 07:03 PM

Edit: sorry, that puts it in automatically, and you want to put it in manually.

Well, now I don't know if this is what you have in mind or not. :(

Here's part of an ftp script using expect.

#!/usr/bin/expect -f

spawn ftp -i 192.168.0.1
expect "Name"
send "fred\r"
expect "Passsword:"
send "mypassword\r"

djcham 10-03-2005 07:21 PM

thanks "homey" haha...

i'll try it out...

is "expect" a command you can use for any program when waiting for a prompt?..i guess so?

stickman 10-03-2005 08:53 PM

Re: passwords in shell scripts
 
Quote:

Originally posted by djcham
I would like to write a script that will SCP, then enter my password and repeat. How do i write a code that wil wait for a prompt and then enter a password? Thanks a lot!
You would be better off using keys for your authentication. Read up on how to generate keys for SSH and ssh-agent.

ns_sanish 10-04-2005 01:57 AM

expect is the answer. If u havent done this b4, then better experiment with auto-expect which generates an expect script based on ur terminal activity.

1) run auto-expect.
2) do some activity. (ex: telnet to a machine and login and do an ls or somerthing)
3) exit (exits from auto-expect)
4) ls -ltr, last file is ur except script. run it


All times are GMT -5. The time now is 11:41 PM.