[英]Sending email with Python script Output and using crontab to send weekly
I have a Python script and I am trying to write a crontab and have the output from the Python script to be outputed to a file which then sends that output to an email address (to the body of the email not the title) that is specified. 我有一个Python脚本,我正在尝试编写一个crontab,并将Python脚本的输出输出到一个文件,然后将该输出发送到指定的电子邮件地址(到电子邮件正文中) 。 My system details and crontab entry is below:
我的系统详细信息和crontab条目如下:
System details:
Python: 2.7
OSX : 10.11
host$ crontab -l
11 11 13 10 4 2016 python pythonscript.py >> weekly.log | mail -s weekly.log myemail@.com
Although when the crontab executes, the email sends me an email message with the subject line saying "weekly.log" with no body. 虽然当crontab执行时,电子邮件会向我发送一封电子邮件,主题行为“weekly.log”,没有正文。
I have also tried crontab with below settings: 我也尝试过以下设置的crontab:
07 22 13 10 4 2016 /root/python/osversion_weekly.py | tee /root/python/osversion`date +\%Y-\%m-\%d-\%H:\%M:\%S`-cron.log | mailx -s "OSLEVEL Report" mymail@server.com
Although I only get an email with Title "OSLEVEL Report" with an empty body 虽然我只收到一封标题为“OSLEVEL Report”的电子邮件,内容空洞
Update: The error I seem to be getting from /var/log/cron is showing "orphan no passwd entry." 更新:我似乎从/ var / log / cron获得的错误显示“orphan no passwd entry”。 Not quite sure what does means, and I havent seen any answers online to resolve this...
不太清楚是什么意思,我没有在网上看到任何答案来解决这个问题......
The >>
makes the python output get appended to the file weekly.log
, after that no input is pushed forward to mail
. >>
使得python输出被附加到文件weekly.log
,之后没有输入被推送到mail
。
You could remove >> weekly.log
and not have a log file or use the program tee
in the pipe. 你可以删除
>> weekly.log
而没有日志文件或使用管道中的程序tee
。 tee
writes to standard output and a file. tee
写入标准输出和文件。
Like this: 像这样:
python pythonscript.py | tee -a weekly.log | mail -s weekly.log myemail@.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.