dimanche 24 mai 2015

ping one device after the other and check availability

I want to run a bash-script on my raspi. The scripts purpose is to check one device in my network for availability. (with ping) if this device is responding, script should end. If its not responding it has to go further and check the availability of 3 specific devices. if one device of that 3 is responding, then send a mail. If none of this devices is responding, then do nothing.

I hope it is recognizable what ive done so far:

#!/bin/bash

array=(192.168.xxx.xxx 192.168.xxx.xxx)
ping -c 1 192.168.xxx.xxx

if [$? -eq 0]; then exit 0
else

for devices in "${array[@]}"

do ping -c 1 $devices &> /dev/null

   if [ $? -eq 0 ]; then exit 0

   fi
fi

done

/usr/sbin/sendmail foo@bar.com < /home/pi/scripts/email.txt

I'm pretty stucked right now, cuz my script skills are frightening bad.

thanks in advance for help!!

greetz ben

Aucun commentaire:

Enregistrer un commentaire