-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-inet.sh
executable file
·63 lines (55 loc) · 1.12 KB
/
test-inet.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
#!/bin/bash
IP=$1
st=0
path_log=$2
loop=$3
if ! [ ${IP} ]; then
IP=8.8.8.8
fi
if ! [ ${loop} ]; then
loop=0
fi
start_help() {
echo "Script to verify access to the Internet.
Usage: test-inet.sh [IP] [path_log] [use_a_loop]
IP - Destination IP
path_log - The path to save the log (optional parameter).
use_a_loop - Execute in a loop = 1 (optional parameter)"
}
start_ping() {
res=1
/bin/ping ${IP} -c 2 > /dev/null 2>&1 && res=0
datal=`date +%Y%m%d`
datat=`date +%T`
if [ ${res} -eq 0 ]; then
if [ ${st} = 0 ]; then
if [ ${path_log} ]; then
echo "${datat} - internet yes" 2>&1 | tee -a ${path_log}"/test-ip-${datal}-${IP}.log"
else
echo "${datat} - internet yes"
fi
st=1
fi
else
if [ ${st} = 1 ]; then
if [ ${path_log} ]; then
echo "${datat} - internet no" 2>&1 | tee -a ${path_log}"/test-ip-${datal}-${IP}.log"
else
echo "${datat} - internet no"
fi
st=0
fi
fi
sleep 2
}
if [ ${IP} = "--help" ]; then
start_help
exit
fi
if [ ${loop} = 1 ]; then
while true; do
start_ping
done
else
start_ping
fi