Took a shortcut on this one. rejigger.sh is a hacky script that has grown over the years to keep some legacy interdependent services running. It outputs all sorts of useful information that is useful when something goes wrong [and more hack needs to be input into the script]. But it is nothing but noise when everything goes right. So today I wrapped the script in another script to mute it unless it fails.
1 2 3 4 5 6 7 8 9 10 11 | #!/bin/bash
tmpfile=$(mktemp)
if timeout 5m /home/dan/Projects/bla/bin/rejigger.sh > "$tmpfile" 2>&1; then
rm "$tmpfile"
exit 0
fi
logger -p Error -t "rejigger.sh" "Something went wrong with $0"
cat $tmpfile
rm $tmpfile
exit 1
|
The only thing fancy here is the timeout command. Very handy.
The output of the script is saved in $tmpfile
. CRON will email its contents
on error and we'll get a nice log message to boot.
comments powered by Disqus