Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
cron handlers
#don't write shell scripts without this...
set -e
cd /my/folder
#Use timeout and flock to run your unreliable script every minute. Run only one copy. Useful against REST APIs for example
timeout --signal=KILL 59 flock -n /tmp/mycommand.lock -c 'mystupid long command'
#Log stdout and stderr. Discard stdout so cron doesn't mail you about it, but still receive mail for errors.
#e.g. in perl print wil generate logs but not mail, while warn and die will generate both
/usr/bin/perl ./ arg1 arg2 > >(logger -t foo) 2> >(logger -s -t foo)
#combine the two
timeout --signal=KILL 59 flock -n /tmp/mycommand.lock -c '/usr/bin/perl ./ arg1 arg2 > >(logger -t foo) 2> >(logger -s -t foo)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.