Skip to content

Instantly share code, notes, and snippets.

@pavelpatrin
Last active March 25, 2016 06:26
Show Gist options
  • Save pavelpatrin/ce19ea52840bfde57c05 to your computer and use it in GitHub Desktop.
Save pavelpatrin/ce19ea52840bfde57c05 to your computer and use it in GitHub Desktop.
#!/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