Last active
March 25, 2016 06:26
-
-
Save pavelpatrin/ce19ea52840bfde57c05 to your computer and use it in GitHub Desktop.
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/sh | |
LOCKFILE="/tmp/script.lock" | |
LOGFILE="/tmp/script.log" | |
COMMAND="/usr/bin/php7 /home/rinat/myscript.php" | |
( | |
if flock -n 200 | |
then | |
echo "["$(date)"] Running command $COMMAND" | tee -a $LOGFILE | |
eval $COMMAND 2>&1 | { | |
while read -r line | |
do echo "["$(date)"] $line" | |
done | |
} | tee -a $LOGFILE | |
echo "["$(date)"] Command finished with code ${PIPESTATUS[0]}" | tee -a $LOGFILE | |
else | |
echo "["$(date)"Failed to acquire lock" | tee -a $LOGFILE | |
fi | |
) 200>$LOCKFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment