Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ip_up(){
- server_ip=$1
- trials=$2
- max_trials=2
- status=0
- echo "server ip is: $server_ip, trial $trials" >&2
- if ping -i 1 -c 3 "$server_ip" &> /dev/null
- then
- status=1
- else
- status=0
- while (( "$trials" < "$max_trials" )); do
- echo -e "$server_ip is down: Trial $trials, checking again after 1 sec" >&2
- sleep 1
- ((trials++))
- ip_up "$server_ip" "$trials"
- done
- fi
- echo "$status"
- }
- status=$(ip_up "$ip" 1)
- echo -e "the returned status is: ====$status====\n"
- <<'COMMENT'
- //results
- $ ./check_servers.sh
- checking box1(173.36.232.6)
- server ip is: 173.36.232.6, trial 1
- 173.36.232.6 is down: Trial 1, checking again after 1 sec
- server ip is: 173.36.232.6, trial 2
- the returned status is: ====0
- 0====
- ./check_servers.sh: line 41: [: 0
- 0: integer expression expected
- Sat Jun 4 15:16:11 EAT 2016 box2 (173.36.232.7) is UP
- checking box2 (173.36.232.7)
- server ip is: 173.36.232.7, trial 1
- the returned status is: ====1====
- COMMENT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement