0

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" marco.fumagalli@mymail.com < /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.

Thanks

1

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" marco.fumagalli@mymail.com
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.