Skip to content

Instantly share code, notes, and snippets.

@KingPin
Created September 11, 2022 23:17
Show Gist options
  • Save KingPin/33d65a5bc32f8011652fd277a4bcfde1 to your computer and use it in GitHub Desktop.
Save KingPin/33d65a5bc32f8011652fd277a4bcfde1 to your computer and use it in GitHub Desktop.
Service restarter on no log output
#!/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