Crontab 不工作 [英] Crontab is not working

查看:36
本文介绍了Crontab 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 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

root 的收件箱中应该有大量由 cron 发送的电子邮件,告诉您诸如 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-readiness:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆