RSync shell脚本无法以CRON运行,手动运行良好

我有一个运行Rsync的简单shell脚本。 它运行良好,如果我从命令行手动调用它,但是当我把它设置为CRON作业,我得到以下错误:

rsync: failed to open exclude file exclude.txt: No such file or directory (2) rsync error: error in file IO (code 11) at exclude.c(1000) [client=2.6.8] 

我在shell脚本中使用以下内容:

 --exclude-from 'exclude.txt' 

该文件存在,脚本运行正常(尊重排除)手动运行时。 由CRON作业和exclude.txt调用的shell脚本位于相同的目录中。

我试图运行的整个脚本如下所示:

 rsync -avrhgo --exclude-from 'exclude.txt' --progress --stats --delete-excluded -e "ssh -p XXXXX" / XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 

您将需要指定排除文件的完整path,因为脚本的工作目录不会自动从启动脚本的位置开始,而是由cron作业所有者的主目录执行。

或者,你可以从你的shell脚本中进入正确的目录。