Cron作业不运行 [英] Cron Job Doesn't Run

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

问题描述

我是新使用crontab,我一直在努力得到一个简单的cron工作。 cron作业的代码如下:

  * / 1 * * * * echojob every minute

所以只是为了验证概念,我想看每一分钟打印。我已尝试使用

  sudo crontab -e 
保存此cro​​n作业
pre>

并通过在目录中保存crontab文件(cronscript)并启用脚本,如下所示:

  crontab〜/ Documents / MyProjects / cronscript 

cron作业所在的位置。
两个相同的作业都正确保存,正如我已通过键入

验证

  sudo crontab -e 


crontab -e



终端和他们两个出现。我确保每个命令后保存一个新的行字符,我检查,以确保cron正在使用

运行

  pgrep然而,我仍然没有得到工作每分钟印刷到终端(每分钟),其中每一分钟。是我相信这些命令应该做的。



我做错了什么?感谢您的帮助!

解决方案

cronjob运行正常,但cron守护进程)无法访问stdout,因此无法向终端输出消息。



但是,您可以使用

$输出您想要的文件b
$ b

  * / 1 * * * * echojob every minute>> $ HOME / filename 

$>

每分钟会将文本输出(并连接)到主目录中名为filename的文件。


I am new to using crontab, and I've been trying to get a simple cron job working. The code for the cron job is as follows:

 */1 * * * * echo "job every minute"

So just for proof-of-concept, I want to see this printed every minute. I have tried saving this cron job using both

 sudo crontab -e

and by saving a crontab file (cronscript) in a directory and enabling the script as follows:

 crontab ~/Documents/MyProjects/cronscript

which is the path for where the cron job is located. Both of the identical jobs are saved properly, as I have verified by typing

  sudo crontab -e

and crontab -e

into terminal and they both appear. I made sure there was a new line character saved after each command, and I checked to make sure cron is running by using

 pgrep cron

However, I am still not getting "job every minute" printed to terminal (every minute) which is what I believe these commands should be doing.

What am I doing wrong? Thanks for the help!

解决方案

The cronjob is running just fine, but the cron daemon (daemons in general as far as I know) have no access to stdout so cannot output messages to the terminal.

To test it you can, however, output what you want to a file using

*/1 * * * * echo "job every minute" >>$HOME/filename

which will output (and concatenate) the text to a file named "filename" in your home directory every minute.

这篇关于Cron作业不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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