I have this cron in my crontab

00 01  *  *  * /srv/python/proj/acquisizione/acquisizioneAOK.sh >> /home/crontab_logs/acquisizioneAOK.out 2>&1; mailx -s "Cron output: acquisizioneAOK" [email protected] < /home/crontab_logs/acquisizioneAOK.out

which writes the stdoutput to a file .out and then sends me an e-mail with that file as text. How can I just empty the file from previous output? I just want an e-mail with the stdoutput of the last cron execution.


2 Answers 2


To overwrite the log file on each execution of the script, replace the >> operator with the > operator.

The >> operator appends the output to the file on each execution, and you would have a continuously growing file with that approach.

The > operator 'clobbers' the file on each execution, which results in any existing data being removed before the redirected output is written.

Going one step further, you could simply pipe the output and error streams from the script to the mailx command directly :

/srv/python/proj/acquisizione/acquisizioneAOK.sh 2>&1 | mailx -s "Cron output: acquisizioneAOK" [email protected]

The redirects of >> will append and > will overwrite. Just wondering though, if not keeping historical data, why not pipe it to mail?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .