Source From Here
- 02-1_ping_server.sh
Execution output:
- 02-2_ping_servers.sh
Execution output:
- #!/bin/bash
- # Author: John Lee
- # Date: 2021/07/24
- # Description: This script will ping a remote host
- # Modified: 2021/07/24
- HOST=${HOST:-localhost}
- ping -c1 ${HOST} &> /dev/null
- if [ $? -eq 0 ]; then
- echo $HOST ok
- else
- echo $HOST NOT ok!
- fi
- 02-2_ping_servers.sh
- #!/bin/bash
- # Author: John Lee
- # Date: 2021/07/24
- # Description: This script will ping multiple hosts given in
- # a file declared in variable `IP_LIST_FILE`
- # Modified: 2021/07/24
- function ping_host {
- ping -c1 $1 &> /dev/null
- if [ $? -eq 0 ]; then
- echo $1 ok
- else
- echo $1 NOT ok!
- fi
- }
- IP_LIST_FILE=${IP_LIST_FILE:-"ip_list_file"}
- if [ -f ${IP_LIST_FILE} ]; then
- for ip in $(cat $IP_LIST_FILE)
- do
- ping_host $ip
- done
- else
- echo "File $IP_LIST_FILE not exist!"
- exit 1
- fi
沒有留言:
張貼留言