Skip to content

Instantly share code, notes, and snippets.

@ferdousulhaque
Created July 12, 2018 08:10
Show Gist options
  • Save ferdousulhaque/ff169a1920321213abff9a4325de5f21 to your computer and use it in GitHub Desktop.
Save ferdousulhaque/ff169a1920321213abff9a4325de5f21 to your computer and use it in GitHub Desktop.
Bash Ping Checking Script with Delay and Count
#!/bin/sh
#Declarations
times=58
ip=IP
while [ 1 ]
do
# Executions
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
result=$(ping -i 1 -c $times $ip | grep 'received')
packetloss=$(echo $result| awk '{print $6}')
if [ "$packetloss" != "0%" ]; then
echo "Ping Loss "$packetloss" at "$timestamp "\n " $result >> /home/user/ping_log_source_to_destination.log
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment