Skip to content

Instantly share code, notes, and snippets.

@EdgeCaseBerg
Last active December 15, 2015 20:57
Show Gist options
  • Select an option

  • Save EdgeCaseBerg/ae0194df23b0c55369fa to your computer and use it in GitHub Desktop.

Select an option

Save EdgeCaseBerg/ae0194df23b0c55369fa to your computer and use it in GitHub Desktop.
Log Monitor
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage: ./monitor.sh /my/log/file.log [sleep time (s)]"
echo "Will output a dot for each second monitored that there are no changes"
echo "Will stop script once no changes are detected to log file"
fi
if [ $# -eq 1 ]; then
LOGFILE=$1
fi
SLEEPTIME=1 #Default sleep time
if [ $# -eq 2 ]; then
LOGFILE=$1
SLEEPTIME=$2
fi
echo "Monitoring $LOGFILE"
ACAPTURE="A"
BCAPTURE="B"
echo "Checking logfile differences every $SLEEPTIME second(s), will stop script once no changes are detected"
echo -n "Start at: " && date
while [[ "$ACAPTURE" != "$BCAPTURE" ]]; do
echo -n "." #Progress indicator that the script is running.
ACAPTURE=`tail $LOGFILE`
sleep $SLEEPTIME;
BCAPTURE=`tail $LOGFILE`
done
echo "" #move down from the dots
echo "No update to log file in last $SLEEPTIME second(s), stopping script"
echo -n "Stopped at: "
date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment