简体   繁体   English

Shell脚本(.sh文件)在crontab中不起作用,但单独起作用

[英]Shell script (.sh file) not working in crontab but it's working alone

30 11 * * * /home/ubuntu/Projects/scripts/Sample.sh 30 11 * * * /home/ubuntu/Projects/scripts/Sample.sh

and the syslog file includes: 并且syslog文件包括:

Jun 28 11:30:01 ip-10-98-125-10 CRON[4225]: (tomcat7) CMD (/home/ubuntu/Projects/scripts/Sample.sh) 6月28日11:30:01 ip-10-98-125-10 CRON [4225]:(tomcat7)CMD(/home/ubuntu/Projects/scripts/Sample.sh)

Please help me; 请帮我; I have been stuck on it! 我一直坚持下去!

Here we need to specify the shell command to run the script. 在这里,我们需要指定shell命令来运行脚本。

30 11 * * * sh /home/ubuntu/Projects/scripts/Sample.sh

It is obvious that you can not even run /home/ubuntu/Projects/scripts/Sample.sh in your interactive shell line. 显然,您甚至/home/ubuntu/Projects/scripts/Sample.sh在交互式shell行中运行/home/ubuntu/Projects/scripts/Sample.sh Because we need to run either ./home/ubuntu/Projects/scripts/Sample.sh (only if Smaple.sh is executable) or sh /home/ubuntu/Projects/scripts/Sample.sh 因为我们需要运行./home/ubuntu/Projects/scripts/Sample.sh (仅在Smaple.sh是可执行文件时)或sh /home/ubuntu/Projects/scripts/Sample.sh

So don't forget sh or bash . 因此,不要忘记shbash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM