你家轩哥
2021-01-18 22:41shell脚本ping整个网段,核心代码基本相同,但执行速度相差特别大有好心的大佬解惑吗?
#!/bin/bash
clear
>ip-up.txt
>ip-down.txt
read -p "please input addr" ipc
for i in {1..254}
do
ping -c 2 -W 1 $ipc.$i &>/dev/null
if [ $? -eq 0 ] ; then
echo "$ipc.$i is up" &>/dev/null >>ip-up.txt
else
echo "$ipc.$i is down" &>/dev/null >>ip-down.txt
fi
done
wait
sort -n -k 4 -t . ip-up.txt -o ip-up.txt
cat ip-up.txt
sort -n -k 4 -t . ip-down.txt -o ip-down.txt
cat ip-down.txt
echo "ping test are finished"
这个是慢的那个。。
#!/bin/bash
#V1.0 2019-09-10
#Ping test shell script by tutor
clear
>ip-up.txt
>ip-down.txt
while true;
do
read -p "Please input the ip segment for ping test(like 192.168.100) : " segment
if [ -z $segment ] ; then
segment="192.168.100"
fi
echo -n "the ip segment is ${segment} , are you sure to continue [y/n] ? "
read action
if [ -z $action ] ; then
break
fi
if [ "$action" = "y" ]; then
break
fi
done
echo "ping test is ready to run! "
for i in {1..254}
do
{
ping -c2 -W1 ${segment}.${i} &>/dev/null
if [ $? -eq 0 ]; then
echo "${segment}.$i is up" &>/dev/null >> ip-up.txt
else
echo "${segment}.$i is down" &>/dev/null >> ip-down.txt
fi
}&
done
wait
sort -n -k 4 -t . ip-up.txt -o ip-up.txt
cat ip-up.txt
sort -n -k 4 -t . ip-down.txt -o ip-down.txt
cat ip-down.txt
echo "ping test are finished!"
这个是快的那个
两个脚本速度差距特别大,求大佬解惑。。。拜托了
- 点赞
- 回答
- 收藏
- 复制链接分享
0条回答
为你推荐
- shell脚本在变量名后面加##*/有啥用?
- linux
- 2个回答
- Linux中shell脚本if判断语句中的逻辑"非"!不就怕结果取反了吗?
- bash
- 1个回答
- 怎样在java代码中调用执行shell脚本呀
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- shell脚本,执行时并修改指定目录下文件内容
- linux
- 3个回答
- 关于shell脚本编写从1、2、3、4中取三个随机的不重复数字所生成的数的问题?
- shell
- 脚本
- 1个回答
换一换