Guest User

Untitled

a guest
Jan 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function valid_ip()
  4. {
  5. local ip=$1
  6. local stat=1
  7.  
  8. if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
  9. OIFS=$IFS
  10. IFS='.'
  11. ip=($ip)
  12. IFS=$OIFS
  13. [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
  14. && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
  15. stat=$?
  16. fi
  17. return $stat
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24. while [[ ($# > 0) ]]
  25. do
  26.  
  27.  
  28. if valid_ip $1
  29. then
  30. ping -c 1 $1 > /dev/null
  31. if [ $? != 0 ]
  32. then
  33. echo "Connection not established"
  34. else
  35.  
  36. ssh $1 ">/dev/null pgrep apache2"
  37. if [ $? == 0 ]
  38. then
  39. echo "Apache process on $1 is up and running"
  40.  
  41. else
  42. echo "Apache process on $1 stopped"
  43. fi
  44.  
  45. fi
  46. shift
  47.  
  48. else
  49. echo "$1 is an inncorrect ip address"
  50. shift
  51.  
  52. fi
  53.  
  54. done
Add Comment
Please, Sign In to add comment