本文介绍了在 Debian Ubuntu 上测试 Crontab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会先说我对使用 Debian Ubuntu 进行命令行编程非常陌生...

I will preface this by saying I am very new to command line programming with Debian Ubuntu...

我一直在尝试在 Debian Ubuntu 服务器上设置 crontab 列表,但无法使其正常工作.这是一个示例:

I have been trying to set up a crontab list on a Debian Ubuntu server but have not been able to get it to work. Here is a sample:

MAILTO=myemail@gmail.com
* * * * * wall test
* * * * * /usr/bin/python2.6 /home/user/test.py > /home/user/clean_tmp_dir.log

当我键入crontab -l"时会显示上述内容,但控制台中不会出现结果输出.test.py"应该生成一个 csv 文件,但没有被创建.

The above shows up when I type "crontab -l" but no resulting output appears in the console. The "test.py" is supposed to generate a csv file but none is being created.

我没有收到任何输出/错误电子邮件.我试图找到一个日志,但var/log/cron"不存在,etc/syslog.conf"也不存在......我试图编辑etc/rsyslog.conf",但得到E212:Can"t 打开文件进行写入"...但是,我已登录.我需要某种特殊的管理权限吗?我是否需要指定用户或root"或其他内容?

I am not receiving any output/error emails. I tried to find a log, but "var/log/cron" does not exist, nor does "etc/syslog.conf"...I tried to edit "etc/rsyslog.conf", but got "E212: Can't open file for writing"...I am logged in, however. Do I need some sort of special administrative privileges? Do I need to specify user or "root" or something?

有谁知道我做错了什么,如何创建/查看日志,或者如何执行任何其他简单的测试?谢谢!

Does anyone know what I'm doing wrong, how I can create/view a log, or how I can perform any other straightforward tests? Thanks!

推荐答案

好的,让我们重新开始.

Ok, let's start over again.

创建一个文件,例如 cron.txt,其内容完全相同(1 行):

Create a file, say cron.txt, with exactly the following contents (1 line):

* * * * * touch $HOME/CRON_IS_RUNNING

(不要手动创建 CRON_IS_RUNNING.)运行

(Do not create CRON_IS_RUNNING manually.) Run

crontab cron.txt

应该安静地不产生输出,然后

which should quietly produce no output, then

crontab -l

应该打印的

* * * * * touch $HOME/CRON_IS_RUNNING

等一下,大概2分钟,然后

Wait a minute or so, perhaps 2 minutes, then

ls -l $HOME/CRON_IS_RUNNING

应该打印类似的东西

-rw-r--r-- 1 yourname yourgroup 0 2011-08-23 20:11 CRON_IS_RUNNING

如果这一切正常,它将确认您可以运行 cron 作业.

If this all works, it will confirm that you can run cron jobs.

如果成功,问题可能出在您的 test.py 命令上.当你从命令行运行它时它工作吗?如果它从命令行运行,但不能从 cron 运行,则 test.py 可能对环境变量有一些依赖性(cron 作业运行时设置的环境变量少于交互式命令通常所做的).

If that's successful, the problem may be with your test.py command. Does it work when you run it from the command line? If it works from the command line but not from cron, test.py might have some dependency on environment variables (cron jobs run with fewer environment variables set than interactive commands typically do).

这篇关于在 Debian Ubuntu 上测试 Crontab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 07:10