shell--使用for循环统计一个网段内的在线主机
方法一:
#!/bin/bash
sum=0 source /etc/init.d/functions for i in 10.0.0.{1..22};do ping -c 1 -w 1 $i &>/dev/null [ $? == 0 ] && sum=$((sum=sum+1)) && action "$i" /bin/true done echo "总共有$sum个主机在线"
方法二:
#!/bin/bash
source /etc/init.d/functions for i in 10.0.0.{1..22};do ping -c 1 -w 1 $i &>/dev/null && action $i & done