February
26
Linux: Using crontab with expect and rsync
Cron can be touchy when doing multiple operations.
I wanted to use rsync over ssh while passing a password using expect.
The best way to do this is to create a script file and then point cron to the script.
One caveat I ran into is that a timeout needs to be set. This setting needs to be long enough that the files are copied before the timeout occurs.Otherwise you do not copy all of the files.
Here is an example:
#!/usr/bin/expect -f
set timeout 86400
spawn /usr/bin/rsync -e ssh -av user@remotelocation:/remotedirectorylocation /localdirectorylocation
expect {
“*Password:*”
{send “userpasswordr”
}
}
expect eof
exit