Linux: Difference between revisions

106 bytes added ,  25 May 2020
Line 452: Line 452:


TMP_FILE=/tmp/inet_up
TMP_FILE=/tmp/inet_up
FAIL_THRESHOLD=1


# Edit this function if you want to do something besides reboot
# Edit this function if you want to do something besides reboot
no_inet_action() {
no_inet_action() {
     rm -f $TMP_FILE
     if [ "$1" -eq 1 ]; then
    shutdown -r now 'No internet.'
        systemctl restart network-manager
    elif [ "$1" -ge 2 ]; then
        rm -f $TMP_FILE
        shutdown -r now "No Internet"
    fi
}
}


Line 464: Line 467:
       echo 0 > $TMP_FILE
       echo 0 > $TMP_FILE
     fi
     fi
     oldnum=`cut -d ',' -f2 $TMP_FILE
     oldnum=$(cut -d ',' -f2 $TMP_FILE)
     newnum=`expr $oldnum + 1`
     newnum=$(("$oldnum" + 1))
     sed -i "s/$oldnum\$/$newnum/g" $TMP_FILE
     sed -i "s/$oldnum\$/$newnum/g" $TMP_FILE
}
}
Line 471: Line 474:
if ping -c5 google.com; then
if ping -c5 google.com; then
     echo 0 > $TMP_FILE
     echo 0 > $TMP_FILE
    date > /tmp/inet_up_last_check
else
else
     increment_tmp_file
     increment_tmp_file
     oldnum=`cut -d ',' -f2 $TMP_FILE
     oldnum=$(cut -d ',' -f2 $TMP_FILE)
     [ $oldnum -ge $FAIL_THRESHOLD ] && no_inet_action
     no_inet_action "$oldnum"
fi
fi
</syntaxhighlight>
</syntaxhighlight>