首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么unison不运行在cronjob中?

为什么unison不运行在cronjob中?
EN

Server Fault用户
提问于 2014-01-22 01:48:55
回答 2查看 3.1K关注 0票数 0

我想要两个基于CentOS的服务器之间的双向数据同步,所以我在我的两个CentOS服务器上安装了Unison。当我从终端运行时,我在root上创建了一个脚本文件,该文件运行一致,工作良好,并同步文件。当我把这个脚本放在crontab中时,同步就不起作用了。我的/etc/crontab

代码语言:javascript
复制
*/1  *  *  *  * root sh /root/syncaaa.sh &>/root/unison-cron.log

以及crontab在/root/unison-cron.log中所放的内容

代码语言:javascript
复制
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并打印出来

代码语言:javascript
复制
+ 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命令在终端上运行良好。

EN

回答 2

Server Fault用户

回答已采纳

发布于 2014-01-22 11:43:05

我解决了这个问题,它是crontab中的HOME=/,它应该是.unison存在的路径。

所以我现在的crontab内容是

代码语言:javascript
复制
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
票数 3
EN

Server Fault用户

发布于 2014-01-22 02:27:18

在脚本顶部添加set -x,以便在运行它之前打印出每个命令。

然后查阅日志文件,看看出了什么问题。

您从Unison引用的错误消息意味着unison命令没有获得正确数量的参数。上面的方法将向您展示实际运行的命令。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/568951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档