Skip to content

Instantly share code, notes, and snippets.

@sasha42
Created January 10, 2017 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sasha42/ddd6157df47330fa9c3858ae62150e5e to your computer and use it in GitHub Desktop.
Save sasha42/ddd6157df47330fa9c3858ae62150e5e to your computer and use it in GitHub Desktop.
#!/bin/bash
# pings 8.8.8.8 and local router, saves into log if offline with timestamp
HOSTS="8.8.8.8 192.168.1.1"
COUNT=4
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
if [ $count -eq 0 ]; then
# 100% failed
echo "Host : $myHost is down (ping failed) at $(date)" > pingdownlog.txt
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment