lunes, 1 de diciembre de 2014

UNIX / Linux Shell Script For Monitoring System network with ping command


by on April 10, 2008 ยท 38 comments
  1. #!/bin/bash
  2. # Simple SHELL script for Linux and UNIX system monitoring with
  3. # ping command
  4. # -------------------------------------------------------------------------
  5. # Copyright (c) 2006 nixCraft project <http://www.cyberciti.biz/fb/>
  6. # This script is licensed under GNU GPL version 2.0 or above
  7. # -------------------------------------------------------------------------
  8. # This script is part of nixCraft shell script collection (NSSC)
  9. # Visit http://bash.cyberciti.biz/ for more information.
  10. # -------------------------------------------------------------------------
  11. # Setup email ID below
  12. # See URL for more info:
  13. # http://www.cyberciti.biz/tips/simple-linux-and-unix-system-monitoring-with-ping-command-and-scripts.html
  14. # -------------------------------------------------------------------------
  15.  
  16. # add ip / hostname separated by white space
  17. HOSTS="cyberciti.biz theos.in router"
  18.  
  19. # no ping request
  20. COUNT=1
  21.  
  22. # email report when
  23. SUBJECT="Ping failed"
  24. EMAILID="me@mydomain.com"
  25. for myHost in $HOSTS
  26. do
  27. count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  28. if [ $count -eq 0 ]; then
  29. # 100% failed
  30. echo "Host : $myHost is down (ping failed) at $(date)" | mail -s "$SUBJECT" $EMAILID
  31. fi
  32. done

0 comentarios:

Publicar un comentario

Suscribirse a Enviar comentarios [Atom]

<< Inicio