Crontab无法正常工作 [英] Crontab is not working
问题描述
我正在尝试使crontab在我的Linux Mint机器上正常运行.
I am trying to make a crontab working in my Linux Mint machine without success.
我使用以下命令打开crontab:
I open crontab with:
sudo crontab -e
然后我以这种方式编辑文件:
and I edit the file this way:
34 10 * * * root /home/dario/Desktop/back_up/prova_crono.sh
或:
34 10 * * * user /home/dario/Desktop/back_up/prova_crono.sh
,但未执行任何作业.
but no job has been performing.
如果我编写以下脚本,则prova_crono.sh脚本可以正常工作:
The script prova_crono.sh is working if I write:
./prova_crono.sh
所以我真的无法理解问题出在哪里.有什么建议吗?
so I really am not able to understand where is the problem. Any suggestions?
最诚挚的问候
推荐答案
好的,问题在于您的cron不接受用户名作为第六字段.删除root
,使您的crontab条目看起来像
Okay, the problem is that your cron does not accept a username as the sixth field. Remove root
so your crontab entry looks like
34 10 * * * /home/dario/Desktop/back_up/prova_crono.sh
cron会在root的收件箱中发送大量电子邮件,告诉您类似command not found: root
的信息.我建议您不要将此crontab安装在root的crontab中,而应安装在您自己的(dario
?)crontab中.这样,失败电子邮件将发送到您的收件箱,而不是root收件箱.
There should be tons of emails in root's inbox sent by cron telling you something like command not found: root
. I suggest you install this crontab not in root's crontab, but in your own (dario
?) crontab. That way, failure emails are sent to your inbox, not root's.
此外,有99%的用户惊讶地发现从cron继承的PATH
几乎是空的.您应该使用
In addition, 99% of users are surprised to find that the PATH
inherited from cron is next to empty. You should set it near the top of your script with
#!/bin/sh
PATH=$(/usr/bin/getconf PATH)
...rest of script...
您可以通过在极为简化的环境中运行脚本来测试其cron就绪性:
You can test the cron-readiness of your script by running it with an extremely reduced environment:
env -i HOME=$HOME /home/dario/Desktop/back_up/prova_crono.sh
如果这有什么问题,请先修复它,然后再将其安装到crontab中.
If that complains about anything, fix it before installing it in the crontab.
这篇关于Crontab无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!