AdjunctProfessorFalcon
AdjunctProfessorFalcon

Reputation: 1840

Including cron job script output in email

I have a python script that, when run via command line, has output that looks like this:

Content-type: application/json


    [
        {
            "url": "http://cf.c.ooyala.com/U0c2podjo_Q8YH6EJrYLRzFyj7s6J7tH/DOcJ-FxaFrRg4gtDEwOjJvdTowczE7j7?ext=.mp4", 
            "tags": [
                "Campus insiders", 
                "ncaa football", 
                " college football", 
                " campus insiders", 
                " pete fiutak", 
                " rich cirminiello", 
                " oregon", 
                " ducks", 
                " mark helfrich", 
                " puddles", 
                " royce freeman", 
                " vernon adams", 
                " jeff locke", 
                " marcus mariota"
            ], 
            "name": "Can Oregon Contend Without Marcus Mariota?", 
            "description": "Campus Insiders' Pete Fiutak and Rich Cirminiello discuss what it will take for Oregon to make it back to the College Football Playoff in 2015."
        }, 
        {
            "url": "http://cf.c.ooyala.com/hnODNodjrHW_FYqIpdIYsfttpl829DeY/DOcJ-FxaFrRg4gtDEwOjJvdTowczE7j7?ext=.mp4", 
            "tags": [
                "Campus insiders", 
                "Fighting Irish", 
                " Notre Dame", 
                " NCAA College Football", 
                " Malik Zaire", 
                " Jaylon Smith", 
                " Ronnie Stanley"
            ], 
            "name": "Why Notre Dame Should Be Excited For 2015", 
            "description": "Malik Zaire.  Jaylon Smith.  Ronnie Stanley.  There's plenty of reasons for Irish fans to be pumped including a home schedule with games vs. Texas, Georgia Tech, and USC.  Still not convinced?  This Campus Insiders hype video will have you begging for the start of the season."
        }, 
        {
            "url": "http://cf.c.ooyala.com/t4YTBodjpxJwd4hVLatB__rLXDZCXGtg/DOcJ-FxaFrRg4gtDEwOjJvdTowczE7j7?ext=.mp4", 
            "tags": [
                "Campus insiders", 
                "ncaa mens basketball", 
                " summer of goodbye", 
                " jordan cornette", 
                " shaka smart", 
                " billy donovan", 
                " oklahoma city thunder", 
                " jerian grant", 
                " willie cauley-stein", 
                " karl-anthony towns", 
                " fred hoiberg", 
                " chicago bulls", 
                " longhorns", 
                " devon booker", 
                " pat connaughton"
            ], 
            "name": "College Basketball's Summer Of The Goodbye", 
            "description": "From coaches finding greener pastures to players hearing their names in the NBA Draft, Campus Insiders' Jordan Cornette is feeling wistful about changes to his beloved college basketball."
        }, 

My cron job configured in Crontab looks like this:

MAILTO = [email protected]

*/15 * * * * /home/local/COMPANY/malvin/SilverChalice_CampusInsiders/SilverChalice_Parser.py > /home/local/COMPANY/malvin/SilverChalice_CampusInsiders`date +\%Y-\%m-\%d-\%H:\%M:\%S`-cron.log | mailx -s "SilverChalice CampusInsiders" [email protected]

I can confirm that the cron job is working in that it does create cron logs in the specified directory with the expected output. However, all I see in my emails are:

Null message body; hope that's ok

What did I do wrong in Crontab? How can I force the output of my py script to show up in the body of an email?

Upvotes: 0

Views: 2071

Answers (1)

Barmar
Barmar

Reputation: 780673

The crontab line should be:

*/15 * * * * /home/local/COMPANY/malvin/SilverChalice_CampusInsiders/SilverChalice_Parser.py | tee /home/local/COMPANY/malvin/SilverChalice_CampusInsiders`date +\%Y-\%m-\%d-\%H:\%M:\%S`-cron.log | mailx -s "SilverChalice CampusInsiders" [email protected]

tee will write to its filename argument and also to stdout, which will pipe to the mailx command.

Upvotes: 1

Related Questions