Cron晚上失败了

我已经建立了一个cron工作,但由于某种原因,它无法在夜间运行。 当我在白天运行它时,同样的工作运行正常(即设置相同的工作在几分钟内运行并等待它运行)。

一些日志:

Jun 17 14:04:01 server CRON[20174]: (root) CMD (/home/server/scripts/sync.sh >> /home/server/logs/nightly.log 2>&1) Jun 17 14:12:01 server CRON[20349]: (root) CMD (/home/server/scripts/sync.sh >> /home/server/logs/nightly.log 2>&1) Jun 17 14:23:01 server CRON[20513]: (root) CMD (/home/server/scripts/sync.sh >> /home/server/logs/nightly.log 2>&1) Jun 18 01:00:01 server CRON[25717]: (root) CMD (/home/server/scripts/sync.sh >> /home/server/logs/nightly.log 2>&1) # this runs during the night Jun 18 01:00:01 server CRON[25706]: (CRON) error (grandchild #25717 failed with exit status 2) # doesn't leave anything behind it, not even the nightly.log file - as though the command itself is invalid) 

cron条目看起来像这样:

 0 1 * * * /home/server/scripts/sync.sh >> /home/server/logs/nightly.log 2>&1 

脚本看起来像这样:

 #!/bin/bash SUCCESS=0 echo "Running nightly automation..." echo "Running xxxx script..." SUCCESS=`/home/server/scripts/xxxx.sh && echo 1` if [ $SUCCESS -eq 1 ]; then echo "xxxx success!" else echo "xxxx fail!" fi echo "Running rsync..." /usr/bin/rsync -am --remove-source-files /path1/ /path2/ --log-file=/home/server/logs/sync.log && echo "rsync success!" 

我已经找到了问题的根源。

事实certificate,我启用了主目录加密,我的脚本位于该加密目录中。 这就是为什么脚本永远不会失败,当我自己运行它 – 我登录了所以路径是有效的。 希望这可能会帮助别人。