3

I have added cronjob -e with below-

* * * * * /usr/bin/python3  /home/user/test.py

But the cronjob is failing everytime. I can test the script while running normally and its working fine.

The cron is required to run every minute and have tested with echo and redirecting output to a file and that works perfectly fine. After trying with both user & root in separate instance it didn't work. I have check the syslog and here is what i can see-

May 20 06:30:01 ubuntu CRON[2145]: (user) CMD (/usr/bin/python3  /home/user/test.py)
May 20 06:30:01 ubuntu CRON[2144]: (CRON) info (No MTA installed, discarding output)
May 20 06:31:01 ubuntu CRON[2148]: (user) CMD (/usr/bin/python3  /home/user/test.py)
May 20 06:31:02 ubuntu CRON[2147]: (CRON) info (No MTA installed, discarding output)
May 20 06:31:29 ubuntu crontab[2150]: (user) BEGIN EDIT (user)
May 20 06:31:37 ubuntu crontab[2150]: (user) REPLACE (user)
May 20 06:31:37 ubuntu crontab[2150]: (user) END EDIT (user)
May 20 06:31:46 ubuntu crontab[2162]: (root) BEGIN EDIT (root)
May 20 06:31:54 ubuntu crontab[2162]: (root) REPLACE (root)
May 20 06:31:54 ubuntu crontab[2162]: (root) END EDIT (root)
May 20 06:32:01 ubuntu cron[862]: (root) RELOAD (crontabs/root)
May 20 06:32:01 ubuntu cron[862]: (user) RELOAD (crontabs/user)
May 20 06:32:01 ubuntu CRON[2177]: (user) CMD (/usr/bin/python3  /home/user/test.py)
May 20 06:32:01 ubuntu CRON[2178]: (root) CMD (/usr/bin/python3  /home/user/test.py)
May 20 06:32:01 ubuntu CRON[2175]: (CRON) info (No MTA installed, discarding output)
May 20 06:32:01 ubuntu CRON[2176]: (CRON) info (No MTA installed, discarding output)
May 20 06:33:01 ubuntu CRON[2183]: (user) CMD (/usr/bin/python3  /home/user/test.py)
May 20 06:33:01 ubuntu CRON[2184]: (root) CMD (/usr/bin/python3  /home/user/test.py)
May 20 06:33:01 ubuntu CRON[2182]: (CRON) info (No MTA installed, discarding output)
May 20 06:33:01 ubuntu CRON[2181]: (CRON) info (No MTA installed, discarding output)

Can't able to figure out what this MTA means here. Read is some forum mailx installation is required as this is a bug. there is no direct mailx installation support on 16.04 may be older version supported it.

Your help is highly appreciated here. Please help me with your inputs.

Thanks,

2 Answers2

0

MTA is mail transfer agent. When you enter

crontab -e

add a line

MAILTO=""

I am not sure it helps.

Anyway, any output to standard output is sent by e-mail if you run it in cron.

nobody
  • 4,412
0

Thanks All,

I fixed it by installing

sudo apt-get install mailutils

I see the desired logs that the mails are getting generated by logs-

May 20 08:02:01 ubuntu CRON[4687]: (user) CMD (/home/path/test.py) May 20 08:02:01 ubuntu postfix/pickup[4397]: CB907603B5: uid=1000 from= May 20 08:02:01 ubuntu postfix/cleanup[4477]: CB907603B5: message-id=<20170520150201.CB907603B5@ubuntu>

But i dont see my script running - but my path is correct and there isn't any issue while just typing the whole the script is running fine.