简体   繁体   English

crontab的sh在Centos中不起作用

[英]sh with crontab is not working in Centos

I am testing an sh script with crontab which simply creates a file 我正在用crontab测试一个sh脚本,该脚本只是创建一个文件

 #!/bin/bash
    PATH=$PATH:/bin:/usr/bin
    TMP_FILE=/home/hmm/AppFlatForRent/i_am_running
    touch "$TMP_FILE"

Now I want to run it on crontab and have used the following but failed 现在,我想在crontab上运行它,并使用了以下内容,但失败了

18 10 * * * sh /home/hmm/AppFlatForRent/hello.sh

Also this one 还有这个

18 10 * * * usr/bin/sh /home/hmm/AppFlatForRent/hello.sh

I am also trying this 我也在尝试这个

23 12 * * * /usr/bin/sh /home/hmm/AppFlatForRent/hello.sh
23 12 * * * sh /home/hmm/AppFlatForRent/hello1.sh
23 12 * * * /home/hmm/AppFlatForRent/hello2.sh

Anyone knows whats the problem? 有人知道出什么问题吗?

Solution: 23 12 * * * sh /home/hmm/AppFlatForRent/hello1.sh 解决方案:23 12 * * * sh /home/hmm/AppFlatForRent/hello1.sh

This works! 这可行!

Give the full path to the shell from cron starting with '/': 从'/'开头的cron给出shell的完整路径:

18 10 * * * /usr/bin/sh /home/hmm/AppFlatForRent/hello.sh

Or just leave the shell out and run the script directly if it is executable: 或者,如果可以执行脚本,则直接退出该外壳程序并直接运行该脚本:

18 10 * * * /home/hmm/AppFlatForRent/hello.sh

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

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