
老李分享:《Linux Shell脚本攻略》 要点(六)
eth0
lo
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.119.2
Server: 192.168.119.2
Address: 192.168.119.2#53
Non-authoritative answer:
www.****.net canonical name = www.****.net.aqb.so.
Name: www.****.net.aqb.so
Address: 14.17.69.22
[root@localhost program_test]# cat list_active_hosts.sh
#!/bin/bash
for ip in 192.168.119.{1..255} ;
do
ping $ip -c 2 &> /dev/null;
if [ $? -eq 0 ];
then
echo $ip is active!
fi
done
[root@localhost program_test]# ./list_active_hosts.sh
192.168.119.1 is active!
192.168.119.2 is active!
5、系统运行时间监视
<pre name="code" class="plain" style="font-size: 14px;">[root@localhost program_test]# cat ssh_test.sh
#!/bin/bash
IP_LIST="192.168.119.1 192.168.119.2 192.168.119.128"
USER="yxy"
for ip in $IP_LIST;
do
utime=$(ssh $USER@$ip uptime | awk '{ print $3 }' )
echo $ip uptime: $utime
done