Skip to content

Instantly share code, notes, and snippets.

@gwww
Last active February 5, 2021 05:17
Show Gist options
  • Select an option

  • Save gwww/07d0619ef430a9c37e7af38918d73b97 to your computer and use it in GitHub Desktop.

Select an option

Save gwww/07d0619ef430a9c37e7af38918d73b97 to your computer and use it in GitHub Desktop.

Revisions

  1. Glenn Waters revised this gist Feb 5, 2021. 1 changed file with 6 additions and 5 deletions.
    11 changes: 6 additions & 5 deletions new-link-down-event.sh
    Original 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$"'
    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
    eval $down_logs | tail -1 >$lastlog_file
    echo "$last_log" >$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
    @@ -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
    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 "`date` $last_saved_log" >>$history_file
    echo "$last_log" >$lastlog_file
    echo Router link DOWN event

    eval $down_logs | tail -5
  2. Glenn Waters created this gist Dec 31, 2020.
    46 changes: 46 additions & 0 deletions new-link-down-event.sh
    Original 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