我是 Linux 的新手,我在我的 Raspberry Pi 上一直在努力解决这个问题,但没有成功。
首先我在/home/myfile.sh
中编写了一个简单的脚本,如下所示:
#!/bin/bash
clear
echo "hi"
然后我执行了 sudo chmod 755/home/myfile.sh
来授予权限。
最后,我使用 crontab -e
修改了 crontab
:
# some comments ...
* * * * * /home/myfile.sh
问题:
当我手动运行脚本时,它工作正常,但是当我在我的 crontab
中设置上面的行时,什么也没有发生。我做错了什么?
最佳答案
为了展示我是如何设法解决我的问题并希望能帮助他人的,我将其作为我自己问题的答案发布在这里:
我通过使用系统范围的 crontab (/etc/crontab
) 而不是 per user crontab ( crontab -e
).
为了澄清这一点,
/etc/crontab
是系统级 crontab:
# m h dom mon dow user command
* * * * * someuser echo 'foo'
虽然 crontab -e
是每个用户 'crontab':
# m h dom mon dow command
* * * * * echo 'foo'
请注意,在每个用户的 crontab 中没有“用户”字段。
关于linux - Raspberry pi 中的 Crontab 不运行非常简单的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34857100/