我正在用 crontab 测试一个 sh 脚本,它只是创建一个文件
#!/bin/bash
PATH=$PATH:/bin:/usr/bin
TMP_FILE=/home/hmm/AppFlatForRent/i_am_running
touch "$TMP_FILE"
现在我想在 crontab 上运行它并使用了以下但失败了
18 10 * * * sh /home/hmm/AppFlatForRent/hello.sh
还有这个
18 10 * * * usr/bin/sh /home/hmm/AppFlatForRent/hello.sh
我也在尝试这个
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
谁知道问题出在哪里?
解决方法: 23 12 * * * sh/home/hmm/AppFlatForRent/hello1.sh
这行得通!
最佳答案
从 cron 以 '/' 开始给出 shell 的完整路径:
18 10 * * * /usr/bin/sh /home/hmm/AppFlatForRent/hello.sh
或者如果它是可执行的,则直接离开 shell 并直接运行脚本:
18 10 * * * /home/hmm/AppFlatForRent/hello.sh
关于linux - 带有 crontab 的 sh 在 Centos 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27385394/