linux - 带有 crontab 的 sh 在 Centos 中不起作用

标签 linux shell sh cron

我正在用 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/

相关文章:

linux - 自动打开和关闭vlc播放器

linux - 把猫放在后台​​卡住我的 shell

bash - 有没有办法检查是否使用 -x 标志执行 shell 脚本

linux - 如何让wc命令递归?

Linux 驱动程序 - 与用户空间共享一个 WaitHandle (-like)

linux - 在没有 --privileged 的​​情况下在 Docker 中使用 ecryptfs。 --device 的适当值?

linux - 如何找到带有标题信息的 ELF 文件/图像的大小?

linux - 如何在shell脚本中捕获信号?

php - 使用 exec Laravel PHP 运行 .sh 文件

linux - 如何使用 xargs 删除 iptables 规则?