Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function valid_ip()
- {
- local ip=$1
- local stat=1
- if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
- OIFS=$IFS
- IFS='.'
- ip=($ip)
- IFS=$OIFS
- [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
- && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
- stat=$?
- fi
- return $stat
- }
- while [[ ($# > 0) ]]
- do
- if valid_ip $1
- then
- ping -c 1 $1 > /dev/null
- if [ $? != 0 ]
- then
- echo "Connection not established"
- else
- ssh $1 ">/dev/null pgrep apache2"
- if [ $? == 0 ]
- then
- echo "Apache process on $1 is up and running"
- else
- echo "Apache process on $1 stopped"
- fi
- fi
- shift
- else
- echo "$1 is an inncorrect ip address"
- shift
- fi
- done
Add Comment
Please, Sign In to add comment