This site requires JavaScript to be enabled
Welcome Guest|
Recent searches
IE BUMPER
KB0017189

How to fix broken user cron jobs in root

Number of views : 9
Article Number : KB0017189
Published on : 2019-11-27
Last modified : 2019-11-27 22:16:14
Knowledge Base : ESM External

*/5 * * * * echo $(date -u) >> /path/to/testlog.txt 2>&1; /usr/local/bin/somescript.sh 2>&1 >> /path/to/testlog.txt | mailx -E -s “subject” email@austin.utexas.edu

This is how I advise customers on creating their own cron jobs that need to run as root. I'll break down what it does.

1. echo $(date -u) >> /path/to/testlog.txt 2>&1; /usr/local/bin/somescript.sh 2>&1 >> /path/to/testlog.txt | mailx -E -s “subject” email@austin.utexas.edu

This part creates a date stamp, then appends it to a logfile, and suppresses stderr and stdout

 

2. echo $(date -u) >> /path/to/testlog.txt 2>&1; /usr/local/bin/somescript.sh 2>&1 >> /path/to/testlog.txt | mailx -E -s “subject” email@austin.utexas.edu

Then it runs the script, and appends all output (stderr and stdout) to the same log.

3. echo $(date -u) >> /path/to/testlog.txt 2>&1; /usr/local/bin/somescript.sh 2>&1 >> /path/to/testlog.txt | mailx -E -s “subject” email@austin.utexas.edu

This will then parse the output of that to email. The -E prevents it from sending a blank email if there is no content to send.

 

 

 

 

 

 

Permalink: utss/KAhome.do?number=KB0017189

Thank You! Your feedback has been submitted.

Feedback