[root@bogon qingshell]# pwd
/root/qingshell
[root@bogon qingshell]# ll
总用量 20
-rw-r--r-- 1 root root 34 2月 19 15:42 ip_list
-rwxr-xr-x 1 root root 532 2月 19 17:15 net_test.sh
-rwxr-xr-x 1 root root 119 2月 19 15:27 ping.sh
drwxr-xr-x 2 root root 4096 2月 20 10:48 report
drwxr-xr-x 2 root root 4096 2月 19 15:42 tmp
++++++++++++++++定义一个IP列表+++++++++++++++++++++++++++++
[root@bogon qingshell]# cat ip_list
8.8.8.8
202.106.0.20
172.16.39.21
+++++++++++++++产生ping的循环+++++++++++++++++++++++++++++++
[root@bogon qingshell]# cat ping.sh
#/bin/bash
iplist=/root/qingshell/ip_list
ping=/root/qingshell/net_test.sh
for i in `cat $iplist`
do
$ping $i &
done
+++++++++++++++切字段,得到想要的结果,并输出++++++++++++++++++++++++++++++
[root@bogon qingshell]# cat net_test.sh
#!/bin/bash
ip=$1
count=5
tmp=/root/qingshell/tmp/ping_$ip.tmp
rep=/root/qingshell/report/$ip.xls
time=$(date +%Y-%m-%d\ %H:%M:%S)
ping $ip -c $count |grep -v $ip >$tmp
packets_transmitted=$(cat $tmp|awk -F "," 'NR==2{print $1}')
received=$(cat $tmp |awk -F "," 'NR==2{print $2}')
packet_loss=$(cat $tmp |awk -F "," 'NR==2{print $3}')
speed_name=$(cat $tmp |awk 'NR==3{print $2}')
speed_num=$(cat $tmp |awk 'NR==3{print $4}')
echo $time --- $packets_transmitted --- $received --- $packet_loss --- $speed_name --- $speed_num >> $rep
++++++++++++++++++++方便以后导出execl++++++++++++++++++++++++++++++
[root@bogon qingshell]# sed -i -r -e "s/ --- /\t/" /root/qingshell/report/*
最后结合mutt+mstmp发送附件给自己的邮箱