hecky

Host Alive?

Jul 4th, 2011
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.62 KB | None | 0 0
  1. #!/bin/bash
  2. echo -e "\t\tScript para verificar si un host esta caido o arriba.\n\t\t\t\tHector Cuevas Cruz"
  3. echo -n "Host: "
  4. read h
  5. alive=`ping -c 1 -i .2 -w 1 $h | grep "received" | cut -d"," -f2 | egrep -o [0-9]`
  6. dead=0
  7.  
  8. unknown=`ping -c 1 -i .2 -w 1 $h 2> out.ping`
  9. cat=`cat out.ping`
  10. if [ "$cat" == "ping: unknown host $h" ]; then
  11.     echo -e "Host Desconocido\nSaliendo del programa..."
  12.     rm -rf out.ping
  13.     exit 0
  14. fi
  15.  
  16. if [ $alive -eq $dead ]; then
  17.     echo -e "Host Caido\n....Mandando mail...--->\n"
  18.     echo "El host $h esta caido" | mail -s "Host Down" hecky
  19.  
  20. else
  21.     echo "El host $h esta OK!!"
  22. fi
  23. rm -rf out.ping
Add Comment
Please, Sign In to add comment