-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfping-report
executable file
·124 lines (91 loc) · 1.45 KB
/
fping-report
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
#
# This script acts as a wrapper for fping, using it in report mode forever.
#
#
# Errors are fatal
#
set -e
function print_syntax() {
echo "Syntax: $0 [--loop] [--log] --num num hostname(s)"
exit 1
}
#
# Wrapper to run fping, with possible logging
#
# {param} string $1 Our command to run
# {param} string $2 The file to log to, if specified
#
function run_fping() {
local CMD=$1
local LOG=$2
if test $LOG
then
echo "" | tee -a ${LOG}
date | tee -a ${LOG}
echo "Running '${CMD}'..." | tee -a ${LOG}
echo "Logging output to '${LOG}'..."
$CMD 2>&1 | tee -a ${LOG}
else
echo ""
date
echo "Running '${CMD}'..."
$CMD
fi
} # End of run_fping()
LOOP=""
NUM=""
HOST=""
LOG=""
#
# Loop through our arguments and parse them
#
while true
do
ARG=$1
ARG_NEXT=$2
if test ! "$ARG"
then
break
elif test $ARG == "--loop"
then
LOOP=1
elif test $ARG == "--num"
then
NUM=$ARG_NEXT
shift
elif test $ARG == "--log"
then
LOG="fping-report-log.txt"
elif test $ARG == "-h"
then
print_syntax
else
HOST="${HOST} $ARG"
fi
shift
done
if test ! "$HOST"
then
print_syntax
elif test ! $NUM
then
print_syntax
fi
#echo "LOOP=${LOOP}, IPV6=${IPV6}, NUM=${NUM}, LOG=${LOG}, HOST=${HOST}" # Debugging
#
# Create our command
#
CMD="fping "
CMD="${CMD} -c ${NUM} -q ${HOST}"
#echo "CMD: $CMD" # Debugging
if test ! $LOOP
then
run_fping "$CMD" $LOG
else
while true
do
run_fping "$CMD" $LOG
#sleep 1
done
fi