Last active
December 15, 2015 20:57
-
-
Save EdgeCaseBerg/ae0194df23b0c55369fa to your computer and use it in GitHub Desktop.
Log Monitor
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/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