Pingip.sh
#!/bin/bash
script="Pingip.sh"
network="192.168.0"
ip_start="$1"
ip_end="$2"
# --- start script ---
trap 'stop' SIGUSR1 SIGINT SIGHUP SIGQUIT SIGTERM SIGSTOP
stop() {
echo -e "\nStop ${script} script ...."
exit 0
}
echo -e "\nStart ${script} Scanner Server ...."
for opt in $(seq ${ip_start} ${ip_end})
do
ping -c 1 -W 1 ${network}.${opt} &> /dev/null && result=0 || result=1
if [ "${result}" == 0 ]; then
echo "Server ${network}.${opt} is UP."
else
echo "Server ${network}.${opt} is DOWN."
fi
done
script 中加入了 trap 來讓 script 執行中可以 Ctrl + C 取消執行,如果沒有加入 trap 就會持續執行到 script 結束
在環境變數中,你必須指定 network 來代表你的網段
使用方式:指定你要的範圍 IP 10 ~ 100
$ ./Pingip.sh 10 100
Start Pingip.sh Scanner Server ....
Server 192.168.0.10 is UP.
Server 192.168.0.11 is UP.
Server 192.168.0.12 is UP.
...
...
Server 192.168.0.10 is DOWN.
Orignal From: 檢測範圍 Server IP 是否 Ping 回應 - bash script
沒有留言:
張貼留言