Last active
February 12, 2017 19:48
-
-
Save danwald/06ae49cb5a64ca1e90655d950ff02750 to your computer and use it in GitHub Desktop.
Flock commands so scripts/cronjobs don't overrun. Send email on failure.
This file contains 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 | |
export from_name='' | |
lockfile=$1 | |
flock=`which flock` | |
#uses mandrill-sendmail via @blackdotsh's https://raw.githubusercontent.com/blackdotsh/mandrillapp-cli/master/sendmail.sh | |
sendmail=$HOME/msendmail.sh | |
dt=`date` | |
$flock -xn "/tmp/$lockfile" echo "${@:2}" | |
if [ $? -eq 1 ] | |
then | |
echo "$lockfile not executed @ $dt. Already running" | |
$sendmail [email protected] $from_name "Failed to run $lockfile @ $dt cmd:${@:2}" | |
exit 1 | |
fi | |
$sendmail [email protected] $from_name "Ran $lockfile @ $dt cmd:${@:2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment