Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86887
  • 博文数量: 12
  • 博客积分: 155
  • 博客等级: 入伍新兵
  • 技术积分: 113
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-19 10:40
文章分类

全部博文(12)

文章存档

2017年(7)

2013年(1)

2012年(4)

分类: 系统运维

2017-06-28 15:58:57

应用场景:现在有一大堆服务器ip需要我去验证是否能ping通,如果单纯用for一个个ip来操作太费时间了,下面的脚本可以指定并发数,批量执行,并发数默认10个,
     如果要修改执行脚本后加 并发数,比如sh checkping.sh20:

[root@localhost ~]#cat checkping.sh
#!/bin/bash
tmpfile=$$.fifo
mkfifo $tmpfile
exec 4<>$tmpfile
rm $tmpfile

thred=$1
thred=${thred:-10}
#
{
for (( i = 1;i<=${thred};i++ ))
do
echo;
done
}>&4

for ip in `cat newsclient.ip`
do
        {
        echo $ip
        ping $ip -c 2
        if [ $? -eq "0" ]
        then
                echo $ip >> newsclient_ping1.ok
        else
                echo $ip >> newsclient_ping1.problem
        fi
        echo >&4
        }&


done <&4


wait

阅读(2900) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~