我想在两个基于CentOS的服务器之间进行双向数据同步,所以我在两个CentOS服务器上安装了Unison 。 我做了一个脚本文件在根本运行一致,工作正常,并同步文件,当我从terminal运行。 当我把这个脚本放在crontab中时,同步根本不起作用。 我的/etc/crontab是
*/1 * * * * root sh /root/syncaaa.sh &>/root/unison-cron.log
什么crontab放在/root/unison-cron.log
Usage: unison [options] or unison root1 root2 [options] or unison profilename [options] For a list of options, type "unison -help". For a tutorial on basic usage, type "unison -doc tutorial". For other documentation, type "unison -doc topics".
我的unison.log文件在通过cron运行时没有更新,只是在通过terminal直接运行时更新。 我检查了cron日志和syncaaa.sh文件运行每个miunte。 任何人都可以build议我该怎么做才能debugging它?
注意:我的服务器1可以无需密码login到服务器2,因为我在server2 authorized_keys中设置了rsa密钥。
>更新1:我试图在脚本中set -x ,并打印
+ chmod -R 0777 /home/user11/folder/ + /usr/bin/unison Usage: unison [options] or unison root1 root2 [options] or unison profilename [options] For a list of options, type "unison -help". For a tutorial on basic usage, type "unison -doc tutorial". For other documentation, type "unison -doc topics"
和/usr/bin/unison命令在terminal上正常工作
我解决了这个问题,这是在crontab中的HOME=/ ,它应该是你的.unison存在的path
所以我现在的crontab内容是
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/home/user1/ # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed */1 * * * * user1 sh syncaaa.sh &>unison-cron.log
在脚本的顶部添加set -x ,所以它会在每个命令运行之前打印出来。
然后查阅日志文件,看看哪里出了问题。
你从Unison引用的错误消息意味着unison命令没有得到正确数量的参数。 上面的方法会告诉你实际运行的命令。