-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrollo-connessione
executable file
·56 lines (49 loc) · 2.18 KB
/
controllo-connessione
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
#!/bin/bash
# ====================================================
# controllo_connessione - controlla la conenssione di rete:
# se manca riavvia la macchina, utile in caso di blackout
# ====================================================
# @authors: Massimo Barbieri ([email protected])
# Alessandro Alboni ([email protected])
# (Add your name if you contribute)
# ====================================================
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU GENERAL PUBLIC LICENSE
# License as published by the Free Software Foundation; either
# version 3 of the License, or any later version.
#
# This library 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.
#
# You should have received a copy of the GNU General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
###########################################################################
TAG="CHECK-CONNESSIONE"
TTL1=$(ping -c 1 192.168.1.1 | grep icmp_req | awk '{print $6}' | sed 's/ttl=//g') #UNIMORE1
TTL2=$(ping -c 1 192.168.1.1 | grep icmp_req | awk '{print $6}' | sed 's/ttl=//g') #UNIMORE2
TTL3=$(ping -c 1 74.125.232.120 | grep icmp_req | awk '{print $6}' | sed 's/ttl=//g') #GOOGLE
TTL4=$(ping -c 1 193.43.189.97 | grep icmp_req | awk '{print $6}' | sed 's/ttl=//g') #GATEWAY
if [ "$TTL1" -ge 0 ] ; then
echo "connessione di rete attiva"
logger La connessione a UNIMORE1 risulta attiva -t $TAG
exit 0
elif [ "$TTL2" -ge 0 ] ; then
echo "connessione di rete attiva"
logger La connessione a UNIMORE2 risulta attiva -t $TAG
exit 0
elif [ "$TTL3" -ge 0 ] ; then
echo "connessione di rete attiva"
logger La connessione GOOGLE3 risulta attiva -t $TAG
exit 0
elif [ "$TTL4" -ge 0 ] ; then
echo "connessione di rete attiva"
logger La connessione GETEWAY4 risulta attiva -t $TAG
# FORSE A QUESTO PUNTO POTREBBE INVIARE UN WARNING ALLA ML
exit 0
else
#echo -e "Riavviato alle ore `date +%H:%M` del `date +%a\ %d\ %b\ %Y`" >> /var/log/riavvio.log
logger Conessione assente riavvio il server -t $TAG
reboot ;
exit 1
fi