我想要两个基于CentOS的服务器之间的双向数据同步,所以我在我的两个CentOS服务器上安装了Unison。当我从终端运行时,我在root上创建了一个脚本文件,该文件运行一致,工作良好,并同步文件。当我把这个脚本放在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运行时不会更新,但是只有在通过终端直接运行时才会更新。我签了cron日志,syncaaa.sh文件每分钟运行一次。有人能建议我如何调试它吗?
注意:我的服务器1可以在没有密码的情况下登录到服务器2,因为我在server2 authorized_keys中设置了rsa密钥。
>Update1:我在脚本中尝试了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命令在终端上运行良好。
发布于 2014-01-22 11:43:05
我解决了这个问题,它是crontab中的HOME=/,它应该是.unison存在的路径。
所以我现在的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发布于 2014-01-22 02:27:18
在脚本顶部添加set -x,以便在运行它之前打印出每个命令。
然后查阅日志文件,看看出了什么问题。
您从Unison引用的错误消息意味着unison命令没有获得正确数量的参数。上面的方法将向您展示实际运行的命令。
https://serverfault.com/questions/568951
复制相似问题