-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpong.sh
More file actions
40 lines (32 loc) · 778 Bytes
/
pong.sh
File metadata and controls
40 lines (32 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
ip_address=$1
trap 'echo -e "\n... $1 pong statistic ...\n$pong_tot pong transmitted, $pong_ok received, $pong_ko loss;\n"; exit' INT
if [ -z "$1" ]; then
exit 0
fi
clear
echo -e "PONG: $1 ( $ip_address )"
while true
do
DATETIME=$(date)
if [[ ${DATETIME} == *:00\ * ]]
then
echo -e
echo -ne ${DATETIME}
echo " Pinging $1"
fi
$(/usr/bin/ping -c 1 -i 1 -w 1 $1 -q 2>&1 >/dev/null)
RET=$?
if [ ${RET} -eq 0 ]; then
echo -ne '!'
let pong_ok=$(($pong_ok+1))
else
echo -ne '.'
let pong_ko=$(($pong_ko+1))
fi
if [ -z "$pong_ko" ]; then pong_ko="0"; fi
if [ -z "$pong_ok" ]; then pong_ok="0"; fi
pong_tot=$(( $pong_ok + $pong_ko ))
sleep 1
done
echo ${#RET}