Animation Ping on Solaris Like Cisco Ping

Hi,

I develop simple animation ping script on Solaris Platform. It is like Cisco ping.

Examples and source code are below.

bash-3.00$ gokcell 152.155.180.8 30
Sending 30 Ping Packets to 152.155.180.8
!!!!!!!!!!!!!.!!!!!!!!!!!!!!!.
% 93.33 success... % 6.66 packet loss...
Start:04-12-2011-03:53:17
End :04-12-2011-03:54:08


bash-3.00$ gokcell 152.155.180.8 60
Sending 60 Ping Packets to 152.155.180.8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
% 100.00 success... % 0 packet loss...
Start:04-12-2011-05:36:40
End :04-12-2011-05:37:44



bash-3.00$ more gokcell
#!/bin/bash
count1=0
count2=0
start=`date +"%d-%m-%Y-%T"`
#Developed by Goksel Yangin for STC Network 
echo
echo Sending $2 Ping Packets to $1
echo
for ((i=1; i<=$2; i++))
do
  sonuc=`/usr/sbin/ping -s $1 64 1 | grep packet | awk '{print $(NF-2)}'`
  sleep 1
  if [[ "$sonuc" == "0%" ]]
  then
    count1=`expr $count1 + 1`
    echo -n !
  else 
    count2=`expr $count2 + 1`
    echo -n .
  fi
done
end=`date +"%d-%m-%Y-%T"`
let "count1*=100"
#let "count1/=$2"
#let kalan=count1%$2 

let "count2*=100"
#let "count2/=$2"
#let kalan2=count2%$2

echo
num1=$(echo "scale=2; $count1 / $2" | bc) 
num2=$(echo "scale=2; $count2 / $2" | bc) 
#printf "\x1b[5m$num1..$num2\x1b[25m"
#echo -n % $num1 success... % $num2 packet loss...
echo -n "`tput blink`% $num1 success... % $num2 packet loss...`tput sgr0`"
echo 
echo Start:$start 
echo End :$end
echo 

Regards,

Goksel Yangin
Computer Engineer

Tested in Linux:

#!/bin/bash 
#or ksh93
[ $# -lt 2 ] && echo "usage:$0 count dest " >&2 && exit 1

Cnt=$1
Dest=$2
Bold=$(tput bold )
BoldOff=$(tput sgr0 )
ok=0
notok=0

start=$(date '+%Y-%m-%d %T' )
echo "Sending $Cnt Ping Packets to $Dest"
i=1
while ((i<=Cnt))
do
        data=$(ping -n -c 1 $Dest | grep "1 packets transmitted" )
        case "$data" in
                *100%*packet*loss*)
                        ((notok+=1))
                        echo -n !
                        ;;
                *)      ((ok+=1))
                        echo -n .
                        ;;
        esac
        sleep 1
        ((i+=1))
done
echo
end=$(date '+%Y-%m-%d %T' )
((success=ok*100 / Cnt ))
((loss=notok*100 / Cnt ))
echo "$Bold % $success success... % $loss packet loss... $BoldOff"
echo "$start - $end "