0

I currently use expect to pass password to rsync to copy files across unix servers
test.sh

 ./expect.sh $password rsync -azvr $username@$host:$file ./$dir 

expect.sh

 #!/usr/bin/expect -f eval spawn [lrange $argv 1 end] #expect "(yes/no)?" #send "yes\r" expect "*?assword:*" send [lindex $argv 0] send \r interact 

if server password got changed but not updated in script, I would like to receive a notification. however currently it would just hangs indefinitely. If I do the following in test.sh

 output=`./expect.sh $password rsync -azvr $username@$host:$file ./$dir` 

Now the script would hang indefintely so I would never get a chance to handle the output. how do I solve this issue?

1
  • use ssh pubkey password less or sshpass(less secure) Commented Feb 15, 2015 at 1:07

1 Answer 1

1

You should edit your expect script to allow for timeout and expected result after rsync.

For example:

... set timeout 60 expect "*?assword:*" send [lindex $argv 0] expect { timeout { send_user "\nFatal Error: unable to rsync \n"; exit 1} "denied" { send_user "\nFatal Error: unable to rsync \n"; exit 1} "sent" } 

The above will exit the script in case of 60 second timeout or if received a denied response in case of bad password. Otherwise if it receives a "sent" text it continues.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.