Crontab: Using Python and sending email attachment
<p>I currently have a python file that is executed by the below crontab. It is currently working where it will run the Python file and it will email the output in the body of the email and also have an attachment with the same data. If I am trying to only have the attachment ( and not show the output of the data in the email), how can I modify my cronjob to do this?</p>

<p>Python file: osversion_weekly.py</p>

<pre><code>#! /usr/bin/python

import commands, os, string
import sys
import fileinput


output = os.system('uptime')
output = os.system('df')
output = os.system('top')
output = os.system('ps')
</code></pre>

<p>Crontab Job:        </p>

<pre><code>04 19 17 10 2 /root/python/osversion_weekly.py | tee /root/python/osversion`date +\%Y-\%m-\%d-\%H:\%M`-cron.csv | mailx -s "Daily Report" -a "/root/python/osversion`date +\%Y-\%m-\%d-\%H:\%M`-cron.csv" myemail@apple.com
</code></pre>

<p>I have a different version of <code>mailx</code> than you so I can't test this, but I suspect you'll get what you want if you replace the command with the following:</p>

<pre><code>/root/python/osversion_weekly.py &gt; /root/python/osversion`date +\%Y-\%m-\%d-\%H:\%M`-cron.csv; echo "" | mailx -s "Daily Report" -a "/root/python/osversion`date +\%Y-\%m-\%d-\%H:\%M`-cron.csv" myemail@apple.com
</code></pre>

<p>This writes the contents of the script to a file and then (hopefully) attaches it.</p>

python linux crontab