-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmax_cycletime.sh
58 lines (52 loc) · 1.96 KB
/
max_cycletime.sh
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
#########################################################################
# max_cycletime.sh #
# Copyright (C) 2010 Psyjo #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 3 of the License, #
# or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
# See the GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, see <http://www.gnu.org/licenses/>. #
#########################################################################
eexit()
{
Ret=$1
shift
echo "$*"
exit ${Ret}
}
doHelp()
{
echo -e "Usage: ./$0 <destination IP>"
}
[[ $# -eq 1 ]] || { doHelp; eexit 1 "Argumentcount does not match"; }
Ip=$(echo $1 | egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}")
[[ ${Ip} ]] || { doHelp; eexit 1 "Argument is not an IP"; }
echo -n "checking host... "
ping -c3 $Ip >/dev/null || eexit 0 "Host unreachable" && echo OK
d_p() { ping -c1 $Ip | sed -n '2p' | awk '{print $7}' | cut -d = -f 2; }
echo "Hit Ctrl+C to exit"
val_old=0
while :
do
val=$(d_p)
if [[ ${val} ]]
then
[[ $(echo "${val} < ${val_old}" | bc) -eq 1 ]] && val=$val_old
val_old=$val
else
val_old=0
val="not reachable"
fi
[[ "$val" != "$last_echo" ]] && echo $val
last_echo=$val
sleep 1
done