Created
October 17, 2017 14:49
-
-
Save bmatthewshea/e437fb73379f2598b5b983a635a00933 to your computer and use it in GitHub Desktop.
A BASH script to monitor a log and restart a service if idle.
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 | |
set -x | |
PATH=$PATH:/opt/scripts | |
SERVICE=ethminer | |
# start infinite loop | |
while : | |
do | |
SECS=$(date +%s) | |
idletime=$(expr $SECS - $(date +%s -r /tmp/ethminer.log)) | |
if [ "$idletime" -gt 120 ] | |
then | |
echo "Restarting service due to no activity for 2 minutes! ($idletime seconds)" | |
sudo service $SERVICE restart # restart or send mail etc here | |
sleep 60 | |
fi | |
# loop repeats until ctrl-c: | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execute with sudo or as root to put the script in background:
screen -dmSL log-monitor ./restart-svc-on-log-failure.sh