Skip to content

Instantly share code, notes, and snippets.

@deadbok
Last active August 29, 2015 13:57
Show Gist options
  • Save deadbok/9417690 to your computer and use it in GitHub Desktop.
Save deadbok/9417690 to your computer and use it in GitHub Desktop.
#!/bin/sh
#Check periodicly if my YouSee supplied Netgear CG3000 router has had another nervous breakdown
#using this script and cron.
#Copyright 2014-2015 Martin Bo Kristensen Grønholdt
#
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.
#Check router.
ping -c 5 -q 192.168.0.1 > /dev/null
if [ $? -ne 0 ]
then
echo >> ~/pinglog.log
echo -n `date` >> ~/pinglog.log
echo -e " - Router is not answering." >> ~/pinglog.log
else
#Check internet connection by pinging google DNS.
ping -c 5 -q 8.8.8.8 > /dev/null
if [ $? -eq 0 ]
then
echo -n "." >> ~/pinglog.log
else
echo >> ~/pinglog.log
echo -n `date` >> ~/pinglog.log
echo -e " - Internet down.\n" >> ~/pinglog.log
fi
fi
#Check for new day and add newline and date
if [ `date +%H%M` -eq "0000" ]
then
echo >> ~/pinglog.log
echo `date` >> ~/pinglog.log
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment