shell脚本查看存活主机

[root@date ~]# cat ping.sh 
#!/bin/bash
network=$1
for host in $(seq 1 254)
do
ping -c 1 $network.$host > /dev/null && result=0 || result=1

if [ "$result" == 0 ]; then
  echo -e "\033[32m $network.$host is up \033[0m"
  echo "$network.$host" > /root/ping-up.txt
else
  echo -e "\033[37m $network.$host is down \033[0m"
  echo "$network.$host" > /root/ping-down.txt
fi
done

[root@date ~]# sh ping.sh 192.168.162 > ping.txt
[root@date ~]# cat ping.txt 
 192.168.162.1 is up 
 192.168.162.2 is down 
 192.168.162.3 is down 
 192.168.162.4 is up 
 192.168.162.5 is down 
 192.168.162.6 is down 
 192.168.162.7 is down 
 192.168.162.8 is up 
 192.168.162.9 is up 
 192.168.162.10 is up 
 192.168.162.11 is up 

你可能感兴趣的:(linux,http,运维,bash,云计算)