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


Copyright 2021. All rights reserved.

Posted February 26, 2014 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B