Copie todo o script abaixo para um arquivo. Dê a este arquivo o nome de "verificador" e transforme-o em executável através do comando:
# chmod a+rwx verificador
#!/bin/sh
########################################
# Script para verificação de Hosts
########################################
# Desenvolvido inicialmente por Djair Dutra C. Jr.
# (djairdutra[at]hotmail.com)
# Versão 0.01
# 27/06/2006
########################################
# Eventuais alterações devem ser feitas logo abaixo com
# data, resumo da alteração, autor e e-mail.
quantmail=`cat mail.conf | grep "@" | wc -l`
quanthost=`cat hosts.conf | wc -l`
if [ "$quanthost" == "0" ]; then
dialog --stdout --msgbox "Não há hosts cadastrados para verificação." 0 0
fi
if [ "$quantmail" -gt "1" ]; then
for i in `cat mail.conf`;do
destino=$i,$destino
done
elif [ "$quantmail" == "1" ]; then
destino=`cat mail.conf`
else
dialog --stdout --msgbox "Não há e-mail cadastrado para envio." 0 0
exit
fi
checa(){
for i in `cat hosts.conf | cut -d , -f 1`;do
tam=`cat hosts.conf | grep -w $i | cut -d , -f 2`
qtd=`cat hosts.conf | grep -w $i | cut -d , -f 3`
min_per=`cat hosts.conf | grep -w $i | cut -d , -f 4`
min_dup=`cat hosts.conf | grep -w $i | cut -d , -f 5`
nome=`cat hosts.conf | grep -w $i | cut -d , -f 6`
ping -c $qtd -s $tam $i > ping.tmp
cat ping.tmp | grep icmp_seq | grep time | grep ms > ping.ok
cat ping.tmp | grep icmp_seq | grep time | grep ms | grep -i DUP > ping.dup
result=`wc -l ping.ok | cut -d ' ' -f1`
perda=`expr $qtd - $result`
dup=`wc -l ping.dup | cut -d ' ' -f1`
if [ "$perda" == "$qtd" ]; then
echo "O Servidor $nome ($i) está PARADO!" | mail -s "SERVIDOR PARADO." $destino
else
if [ "$perda" -gt "$min_per" ]; then
echo "O Servidor $nome ($i) está com perda de pacote.
Env:$qtd
Per:$perda" | mail -s "PERDA DE PACOTES" $destino
fi
fi
if [ "$dup" -gt "$min_dup" ]; then
echo "O Servidor $nome ($i) está com excesso de pacotes duplicados.
Env:$qtd
Dup:$dup" | mail -s "PACOTES DUPLICADOS" $destino
fi
done
rm -rf ping.tmp
}
checa