Last active
April 28, 2016 07:05
-
-
Save afirth/095b6a2b6698257b56ae to your computer and use it in GitHub Desktop.
cron handlers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#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 ./foo.pl 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 ./foo.pl 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