[英]crontab suggested error :/bin/sh .backup.sh no such file or directory
I use the command crontab -e
to execute a shell script at regular intervals. 我使用命令
crontab -e
定期执行Shell脚本。
But something wrong with it. 但是这有问题。
The shell script is located in /opt/oneinstack/oneinstack
,so my crontab is : shell脚本位于
/opt/oneinstack/oneinstack
,所以我的crontab是:
0 1 * * * cd /opt/oneinstack/oneinstack;./backup.sh >> /data/back.log 2>&1 &
0 1 * * * cd /opt/oneinstack/oneinstack;./backup.sh >> /data/back.log 2>&1&
The permission for the backup.sh file is 755. backup.sh文件的权限为755。
The user using the crontab -e
command is root 使用
crontab -e
命令的用户是root
Message in /data/back.log is /bin/sh no such file or directory .
/data/back.log中的消息是
/bin/sh no such file or directory .
Just like the title. 就像标题一样。
Manual execution the backup.sh
is no problem. 手动执行
backup.sh
是没有问题的。
What's wrong with it? 它出什么问题了? And how can I fixed it?
我该如何解决?
Expect someone to help me.Thanks a lot!! 期待有人帮助我。非常感谢!
Try setting the following before the crontab list. 尝试在crontab列表之前设置以下内容。 For example, if this line is at the top:
例如,如果此行在顶部:
0 1 * * * cd /opt/oneinstack/oneinstack;./backup.sh >> /data/back.log 2>&1 &
then it looks like this: 那么它看起来像这样:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
0 1 * * * cd /opt/oneinstack/oneinstack;./backup.sh >> /data/back.log 2>&1 &
In addition: Like @Ugur mentioned, it is unnecessary to cd, if you take care of the paths correctly in the backup.sh
. 另外:像提到的@Ugur一样,如果可以正确地
backup.sh
中的路径,则不必使用cd。 For example: 例如:
ROOTPATH="/path/to/data"
TARTGETPATH="/path/to/target"
FileToBackup="${ROOTPATH}/myfile"
rsync $FileToBackup $TARGETPATH/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.