我有一个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脚本的输出显示在电子邮件正文中?
答案 0 :(得分:1)
if (num % 1 == 0)
行应为:
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
命令。