0

1. No MTA installed

$ sudo grep CRON /var/log/syslog

...
Oct 20 12:28:01 tb-live CRON[13160]: (CRON) info (No MTA installed, discarding output)
...

Solution:

$ sudo apt-get install postfix

2. Command source not found

To check the log of crontab, you can also checkout at /var/mail/youruser
And here we found the /bin/sh: 1: source: not found.

From youruser@tb-live  Mon Oct 29 05:57:01 2018
Return-Path: <youruser@tb-live>
X-Original-To: youruser
Delivered-To: youruser@tb-live
Received: by tb-live (Postfix, from userid 1000)
    id B3DDCBD531; Mon, 29 Oct 2018 05:57:01 +0000 (UTC)
From: root@tb-live (Cron Daemon)
To: youruser@tb-live
Subject: Cron <youruser@tb-live> source /home/youruser/envs/env-yourproject/bin/activate && cd /home/youruser/envs/env-yourproject/yourproject-django && ./manage.py check_expiration_date > /home/youruser/cron-expiration.log 2>&1
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/youruser>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=youruser>
Message-Id: <20181029055701.B3DDCBD531@tb-live>
Date: Mon, 29 Oct 2018 05:57:01 +0000 (UTC)

/bin/sh: 1: source: not found

You have mail in /var/mail/youruser

So, we need to change the /bin/sh into /bin/bash to fix the problem. but why?
Finally, we just nedd to add SHELL=/bin/bash into top line of crontab editor.

SHELL=/bin/bash

# 1. upproxy every 1 hour, see: https://crontab.guru/every-1-hour
0 * * * * source /home/youruser/envs/env-yourproject/bin/activate && cd /home/youruser/envs/env-yourproject/yourproject-django && ./manage.py upproxy > /home/youruser/cron-proxy.log 2>&1
bash server linux solution django python problem

Your Answer

blog comments powered by Disqus