在电子邮件中包含 cron 作业脚本输出

Including cron job script output in email

我有一个 python 脚本,当通过命令行 运行 时,它的输出如下所示:

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."
        }, 

我在 Crontab 中配置的 cron 作业如下所示:

MAILTO = my@email.com

*/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" my@email.com

我可以确认 cron 作业正在运行,因为它确实在指定目录中创建了具有预期输出的 cron 日志。但是,我在电子邮件中看到的是:

Null message body; hope that's ok

我在 Crontab 中做错了什么?如何强制我的 py 脚本的输出显示在电子邮件正文中?

crontab 行应该是:

*/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" my@email.com

tee 将写入其文件名参数以及 stdout,后者将通过管道传输至 mailx 命令。