Last active
February 5, 2021 05:17
-
-
Save gwww/07d0619ef430a9c37e7af38918d73b97 to your computer and use it in GitHub Desktop.
Revisions
-
Glenn Waters revised this gist
Feb 5, 2021 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,16 +2,16 @@ lastlog_file="/home/admin/link-down/lastlog.txt" history_file="/home/admin/link-down/history.txt" down_logs="clog /var/log/system.log | grep 'link state changed to DOWN$'" last_log=`eval $down_logs | tail -1` if [ ! -e $lastlog_file ]; then echo "$last_log" >$lastlog_file touch -A -235959 $lastlog_file echo "`date` Created $lastlog_file" >>$history_file exit 0 fi read last_saved_log <$lastlog_file if [ "$last_saved_log" = "$last_log" ]; then @@ -32,14 +32,15 @@ if [ "$last_event_time" = "" ]; then echo "`date` Quelched: $last_log" >>$history_file # Update lastlog but preserve mtime from existing lastlog file echo "$last_log" >$lastlog_file.new touch -r $lastlog_file $lastlog_file.new mv $lastlog_file.new $lastlog_file exit 0 fi echo "`date` DOWN event detected: $last_log" >>$history_file echo "`date` $last_saved_log" >>$history_file echo "$last_log" >$lastlog_file echo Router link DOWN event eval $down_logs | tail -5 -
Glenn Waters created this gist
Dec 31, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ #!/bin/sh lastlog_file="/home/admin/link-down/lastlog.txt" history_file="/home/admin/link-down/history.txt" down_logs='clog /var/log/system.log | grep "link state changed to DOWN$"' if [ ! -e $lastlog_file ]; then eval $down_logs | tail -1 >$lastlog_file touch -A -235959 $lastlog_file echo "`date` Created $lastlog_file" >>$history_file exit 0 fi last_log=`eval $down_logs | tail -1` read last_saved_log <$lastlog_file if [ "$last_saved_log" = "$last_log" ]; then # echo "`date` No new DOWN events." >>$history_file exit 0 fi if [ "$last_log" = "" ]; then echo "`date` Log file rolled/rotated or cleared." >>$history_file rm $lastlog_file touch $lastlog_file exit 0 fi # Limit reports to no more than once per 480 minutes (6 hours) last_event_time=`find /home/admin/link-down -name lastlog.txt -mmin +480` if [ "$last_event_time" = "" ]; then echo "`date` Quelched: $last_log" >>$history_file # Update lastlog but preserve mtime from existing lastlog file echo $last_log >$lastlog_file.new touch -r $lastlog_file $lastlog_file.new mv $lastlog_file.new $lastlog_file exit 0 fi echo "`date` DOWN event detected: $last_log" >>$history_file echo $last_log >$lastlog_file echo Router link DOWN event eval $down_logs | tail -5 exit 1