-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping_test.sh
executable file
·77 lines (64 loc) · 1.98 KB
/
ping_test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#usage
#./ping_test.sh -d [duration - in seconds] -f [log file]
#----- help function -----
function helper {
echo "Usage:
ping_test [duration] [OPTION...]
Application Options:
-d Duration (in seconds)
-f Log file (use current datetime is not specified)
-h Help
-H Host (use google.com if not specified)
-i Interval between pings (in seconds)
-v Verbose mode
-V Version
"
}
#----- Main program -----
#
while getopts d:f:hH:i:vV option
do
case "${option}"
in
d) duration=${OPTARG};;
f) file=${OPTARG}.log;;
h) helper
aux_helper=$"1";;
H) host=${OPTARG};;
i) interval=${OPTARG};;
v) verbose=$"1";;
V) echo "Version 0.36 beta"
aux_helper=$"1";;
esac
done
#echo $host
if [ "$aux_helper" "==" "" ]; then
#If no log file is specified
if [ "$file" "==" "" ]; then
file="ping_"$(date +%Y_%m_%d_%H_%M_%S).log
fi
#If no host is specified
if [ "$host" "==" "" ]; then
host=$"google.com"
fi
#If no interval is specified
if [ "$interval" "==" "" ] || [ "$interval" "<" "0.2" ]; then
interval=$"1"
fi
#if duration is specified
if ! [ "$duration" "==" "" ] && ! [ -n "$(printf '%s\n' "$duration" | sed 's/[0-9]//g')" ]; then
if [[ $verbose == "1" ]]; then
echo " Duration time is $duration seconds
Host is $host
Log file is $file
Interval is $interval
Executing..."
fi
#echo "ping $host -n -W 1 -i $interval -w $duration |& xargs -L 1 -I '{}' date '+%Y-%m-%d %H:%M:%S: {}' |& tee $file"
ping $host -n -W 1 -i $interval -w $duration |& xargs -L 1 -I '{}' date '+%Y-%m-%d %H:%M:%S: {}' |& tee $file
else
echo "Invalid or missing arguments"
helper
fi
fi