2014-05-08 3 views
0

J'ai une question à propos d'un script que j'ai trouvé pour surveiller un périphérique sur mon réseau.Script de surveillance réseau pour Debian

Le script:

#!/bin/bash 

HOSTS="192.168.11.1" 
COUNT=1 


SUBJECT="Ping failed" 
EMAILID="[email protected]" 
for myHost in $HOSTS 
do 
count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print  $1 }') 
if [ $count -eq 0 ]; then 

echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID 
fi 
done 

Lors de l'exécution du script, il semble fonctionner, mais il n'envoie rien à l'adresse e-mail. Quelqu'un pourrait-il me dire ce que je fais mal? Modifiez votre script comme suit et réessayez.

+0

Essayez de changer '' mail' à mailx' –

+0

Cela ne me aide pas beaucoup. L'utilisation d'une ancienne version du courrier ne résout pas le problème. – user3183115

Répondre

0

#!/bin/bash 

HOSTS="192.168.11.1" 
COUNT=1 
SUBJECT="Ping failed" 
EMAILID="[email protected]" 

for myHost in $HOSTS 
do 

count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }') 

if [ $count -eq 0 ]; then 

cd ~ 

if [ -s PING_FILE ] 
then 
rm PING_FILE 
fi 

echo "Host : $myHost is down (ping failed) at $(date)" > PING_FILE 
mail -s "$SUBJECT" $EMAILID < PING_FILE 

#if you want to get the file itself use the below code # 
mutt -s "$SUBJECT" -a PING_FILE - $EMAILID < PING_FILE 

fi 

done 

Cordialement,

Dominic

+0

J'ai essayé cela et il n'enverrait toujours pas l'email. J'ai l'impression qu'il y a une sorte d'erreur d'argument commençant à la commande grep. Je suis vraiment déconcerté .. – user3183115

Questions connexes