crontab执行expect脚本

通过rsync的ssh差异备份方式同步本地目录到远端目录,expect代码如下,命令行手动执行即可

# cat expecttool
#!/usr/bin/expect -f

set timeout 7200;

spawn  /usr/bin/rsync -avz -e "/usr/bin/ssh" /path/to/local/dir/ remoteuser@remotehost:/path/to/remote/dir/
expect { 
"*yes/no*" {
        send "yes\r";
        exp_continue
}
"*assword*" {
        send "pasword\r";
}                     
}
interact

如果要放到crontab任务中,需要把interact替换为 

expect eof

exit

这种方式在crontab和命令行均可运行

猜你喜欢

转载自ciaos.iteye.com/blog/2175759
今日推荐