Created
September 11, 2022 23:17
-
-
Save KingPin/33d65a5bc32f8011652fd277a4bcfde1 to your computer and use it in GitHub Desktop.
Service restarter on no log output
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 | |
# simple script to check logs, if no entries have been made in 45 seconds restart | |
set -x | |
PATH=$PATH:/usr/sbin | |
TS=$(date +%s) | |
timer1=$(expr $TS - $(date +%s -r /path/to/some/file.log)) # make sure to set the log path here | |
if [ "$timer1" -gt 45 ] | |
then | |
echo $timer1 | |
echo "restarting service due to no activity for 45 seconds" | |
sudo service mycoolservice restart # you can change this for something else such as sending email or even rebooting the machine. | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment