虚拟环境中的Django项目的crontab问题:"邮寄1个字节的输出;但得到状态0x004b,#012"

时间:2015-03-19 18:23:51

标签: python django virtualenv crontab

我有一个django项目是否有任务向所有用户发送每周电子邮件通知。以下是方法的步骤: -

1.处理管理命令,发送每周电子邮件通知。

2.编辑crontab如下: -

$ sudo crontab -e
#For testing purposes I have edited as below
 1 * * * * pathto/virtualenv pathto/manage.py notify_email

3.重新启动crontab

$sudo service cron restart
cron stop/waiting
cron start/running, process 16218

4.检查我在下面尝试过的日志状态

$tail -n 10 /var/log/syslog

Mar 19 13:36:08 praneeth-Latitude-E6400 cron[15293]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
Mar 19 13:37:01 praneeth-Latitude-E6400 CRON[15364]: (praneeth) CMD (/home/praneeth/wru-pam/venv/bin/python3.4 /home/praneeth/wru-pam/pam_site/manage.py notify_about_changes)
Mar 19 13:37:02 praneeth-Latitude-E6400 postfix/sendmail[15367]: fatal: open /etc/postfix/main.cf: No such file or directory
Mar 19 13:37:02 praneeth-Latitude-E6400 CRON[15363]: (praneeth) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Mar 19 13:38:01 praneeth-Latitude-E6400 CRON[15416]: (praneeth) CMD (/home/praneeth/wru-pam/venv/bin/python3.4 /home/praneeth/wru-pam/pam_site/manage.py notify_about_changes)
Mar 19 13:38:01 praneeth-Latitude-E6400 postfix/sendmail[15418]: fatal: open /etc/postfix/main.cf: No such file or directory
Mar 19 13:38:01 praneeth-Latitude-E6400 CRON[15415]: (praneeth) MAIL (mailed 1 byte of output; but got status 0x004b, #012)
Mar 19 13:39:01 praneeth-Latitude-E6400 CRON[15457]: (praneeth) CMD (/home/praneeth/wru-pam/venv/bin/python3.4 /home/praneeth/wru-pam/pam_site/manage.py notify_about_changes)
Mar 19 13:39:01 praneeth-Latitude-E6400 postfix/sendmail[15459]: fatal: open /etc/postfix/main.cf: No such file or directory
Mar 19 13:39:01 praneeth-Latitude-E6400 CRON[15456]: (praneeth) MAIL (mailed 1 byte of output; but got status 0x004b, #012)

5.我已经通过以下forum解决方案来查看终端中的邮件,并在我下载邮件时找到1到43个条目

$sudo mail
N  1 Cron Daemon        Mon Mar 16 14:21   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N  2 Cron Daemon        Mon Mar 16 14:22   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N  3 Cron Daemon        Mon Mar 16 14:23   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N  4 Cron Daemon        Mon Mar 16 14:24   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N  5 Cron Daemon        Mon Mar 16 14:25   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N  6 Cron Daemon        Mon Mar 16 14:26   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N  7 Cron Daemon        Mon Mar 16 14:27   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N  8 Cron Daemon        Mon Mar 16 14:28   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N  9 Cron Daemon        Mon Mar 16 14:29   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 10 Cron Daemon        Mon Mar 16 14:30   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 11 Cron Daemon        Mon Mar 16 14:31   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 12 Cron Daemon        Mon Mar 16 14:32   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 13 Cron Daemon        Mon Mar 16 14:33   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 14 Cron Daemon        Mon Mar 16 14:34   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 15 Cron Daemon        Mon Mar 16 14:35   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 16 Cron Daemon        Mon Mar 16 14:36   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 17 Cron Daemon        Mon Mar 16 14:37   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 18 Cron Daemon        Mon Mar 16 14:38   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 19 Cron Daemon        Mon Mar 16 14:39   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 20 Cron Daemon        Mon Mar 16 14:40   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 21 Cron Daemon        Mon Mar 16 14:41   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 22 Cron Daemon        Mon Mar 16 14:42   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 23 Cron Daemon        Mon Mar 16 14:43   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 24 Cron Daemon        Mon Mar 16 14:44   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 25 Cron Daemon        Mon Mar 16 14:45   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 26 Cron Daemon        Mon Mar 16 14:46   22/1194  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 27 Cron Daemon        Mon Mar 16 14:47   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 28 Cron Daemon        Mon Mar 16 14:48   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 29 Cron Daemon        Mon Mar 16 14:49   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 30 Cron Daemon        Mon Mar 16 14:50   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 31 Cron Daemon        Mon Mar 16 14:51   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 32 Cron Daemon        Mon Mar 16 14:52   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 33 Cron Daemon        Mon Mar 16 14:53   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 34 Cron Daemon        Mon Mar 16 14:54   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 35 Cron Daemon        Mon Mar 16 14:55   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 36 Cron Daemon        Mon Mar 16 14:56   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 37 Cron Daemon        Mon Mar 16 14:57   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 38 Cron Daemon        Mon Mar 16 14:58   54/3457  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 39 Cron Daemon        Mon Mar 16 14:59   21/1323  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 40 Cron Daemon        Mon Mar 16 15:00   21/1323  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 41 Cron Daemon        Mon Mar 16 15:01   21/1323  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 42 Cron Daemon        Mon Mar 16 15:02   21/1323  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet
 N 43 Cron Daemon        Mon Mar 16 15:03   21/1323  Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneet

如果我输入1,我收到如下信息: - 消息9:

From root@praneeth-Latitude-E6400.corp.ad.wrs.com  Mon Mar 16 14:29:02 2015
Return-Path: <root@praneeth-Latitude-E6400.corp.ad.wrs.com>
Date: Mon, 16 Mar 2015 14:29:01 -0400
From: root@praneeth-Latitude-E6400.corp.ad.wrs.com (Cron Daemon)
To: root@praneeth-Latitude-E6400.corp.ad.wrs.com
Subject: Cron <root@praneeth-Latitude-E6400> cd /home/praneeth/wru-pam/pam_site && /home/praneeth/wru-pam/venv/bin/python3.4 manage.py notify_about_changes
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Status: R

发送每周电子邮件通知的解决方案的另一方&#34;我能够通过kronos,django-celery与rabbitmq经纪人轻松地发送自动电子邮件通知。 但我想使用crontab 尽可能简化任务。&#34;

我很感激指导提前致谢

2 个答案:

答案 0 :(得分:0)

也许this可以帮助您解决cron抛出的后缀错误:

一种可能的解决方案是重新配置postfix。可以使用以下命令重新配置:

sudo dpkg-reconfigure postfix

将显示用户界面。在每个屏幕上,选择以下值:

  • 确定
  • 互联网网站
  • NONE
  • mail.example.com
  • mail.example.com,localhost.localdomain,localhost
  • 没有
  • 127.0.0.0/8,192.168.0 / 24
  • 0
  • +
  • 所有

您可能需要编辑/etc/postfix/main.conf来更新邮件主机名。

答案 1 :(得分:0)

最后,我能够解决crontab中的前三个步骤,通过重新编辑crontab来发送电子邮件通知

$*/1 * * * *  /home/praneeth/wru-pam/venv/bin/python3.4 /home/praneeth/wru-pam/pam_site/manage.py notify_about_changes --settings=project.settings.development

另外我发现第4步和第5步不是检查crontab日志状态的正确方法。