carbon_ghost
carbon_ghost

Reputation: 1124

Trouble with Cron sending email after python script execution

I have a python script I'm successfully executing every night at midnight. It's outputting the log file, however, I want it to also send an email with the log contents.

I've read this is pretty use to do, but I've had no luck thus far. I've tried this but it does not work. Does anyone else have some other suggestions?

I'm running Ubuntu 14.04, if that makes a difference with the mail smtp.

[email protected]

0 0 * * * /usr/bin/python /home/grant/Developer/Projects/StudyBug/Main.py > /home/grant/Desktop/Studybuglog.log 2>&1

Upvotes: 0

Views: 580

Answers (1)

Slartibartfast
Slartibartfast

Reputation: 1700

Cron will send everything sent by the command to its standard output (what would be sent to the screen if you ran the command from the command line) in an email to the email address in MAILTO.

Unfortunately for you, you are changing the behaviour of this command using shell redirection. If you ran the command exactly as written above, there would be nothing shown on the screen because everything is written to the file (because you redirect standard output to the file using the '>' operator).

If you want an email, remove the >, and everything after it and then test.

If you also want to write to a log file, you might try the 'tee' command, or changing your script to take a log file as a command line argument, and write to both the log file and the standard output.

Upvotes: 1

Related Questions