rsync + crontab + expect 快速搭建同步

一. 首先安装如下软件
# yum -y install expect rsync

二. 其次创建编写脚本 rsync_expect.exp 并修改为可执行文件
# vim rsync_expect.exp
#!/usr/bin/expect
set timeout 3000
spawn rsync -azvP --delete /rsyncmaster/ root@ip_address:/rsyncslave/
expect "password:"
send "password "
expect eof
exit
# chmod 744 rsync_expect.exp

三. 最后编辑crontab 并创建日志文件
# crontab -e
*/1 * * * * /usr/bin/expect /rsynctest/rsync_expect.exp >> /rsynctest/rsync_expect.log 2>&1


备注:
-> expect 程序对话与互动程序
-> #!/usr/bin/expect 脚本用expect程序执行
-> set timeout 3000 超时
-> spawn 启动新的进程
-> expect expect 就是 expect的内部命令,从进程接收字符串
-> send 向进程发送字符串
-> 回车符
-> eof 结束
-> exit 退出
-> chmod 744 可执行
-> crontab -e 编辑任务
-> * * * * * Program
第一列:分
第二列:小
第三列:日
第四列:月
第五列:周
第六列:需要执行的命令或软件
“*”表示取值范围内的数字
“/”表示“每” “*/1”第一个每1分钟
“-”表示从某个数字到某个数字
“,”分开几个离散的数字
->“>>” 重定向追加
-> 2>&1 指将标准信息输出路径指定为错误信息输出路径(简单的说对的和异常信息都录入)

原文地址:https://www.cnblogs.com/xkcp008/p/9718289.html