linux 用于测试指定段的主机的连通性的脚本
2011-07-24 13:45
204 查看
题目如下:
#!/bin/bash
#the script's name is:*********use to test the host*********
#the author is :Ro
#the version is :Ro-4-10
let PIP=$1
NetIP='192.168.1.'
if [ $1 -gt 254 ];then
echo "The fist number should <=254"
elif [ $2 -gt 254 ];then
echo "The second number should <=254"
elif [ $1 -gt $2 ];then
echo "The first number should <= the second number"
else
while [ $PIP -le $2 ];do
ping -c1 -W1 $NetIP$PIP > /dev/null && echo "The host $NetIP$PIP is UP." >> /tmp/host_state || echo "The host $NetIP$PIP is DOWN." >> /tmp/host_state
let PIP++
done
echo "=============================="
cat /tmp/host_state
echo "=============================="
sed '1,$s/\(.*DOWN\)./#\1/g' /tmp/host_state
echo "=============================="
sort -t " " -k 5 /tmp/host_state | cut -d" " -f5 | uniq -c
echo "=============================="
rm -rf /tmp/host_state
fi
测试结果:
这个脚本主要运用到了循环语句,条件判断,如IP地址的取值范围,变量的赋值等进行判断,使用if语句和while语句结合起来达到效果,还有排序等知识点,在
以后的网络中的运用也是很广泛的本文出自 “Ro の博客” 博客,请务必保留此出处http://luoweiro.blog.51cto.com/2186161/621983
#!/bin/bash
#the script's name is:*********use to test the host*********
#the author is :Ro
#the version is :Ro-4-10
let PIP=$1
NetIP='192.168.1.'
if [ $1 -gt 254 ];then
echo "The fist number should <=254"
elif [ $2 -gt 254 ];then
echo "The second number should <=254"
elif [ $1 -gt $2 ];then
echo "The first number should <= the second number"
else
while [ $PIP -le $2 ];do
ping -c1 -W1 $NetIP$PIP > /dev/null && echo "The host $NetIP$PIP is UP." >> /tmp/host_state || echo "The host $NetIP$PIP is DOWN." >> /tmp/host_state
let PIP++
done
echo "=============================="
cat /tmp/host_state
echo "=============================="
sed '1,$s/\(.*DOWN\)./#\1/g' /tmp/host_state
echo "=============================="
sort -t " " -k 5 /tmp/host_state | cut -d" " -f5 | uniq -c
echo "=============================="
rm -rf /tmp/host_state
fi
测试结果:
这个脚本主要运用到了循环语句,条件判断,如IP地址的取值范围,变量的赋值等进行判断,使用if语句和while语句结合起来达到效果,还有排序等知识点,在
以后的网络中的运用也是很广泛的本文出自 “Ro の博客” 博客,请务必保留此出处http://luoweiro.blog.51cto.com/2186161/621983
相关文章推荐
- shell脚本测试某网段内主机连通性
- shell脚本之测试某网段内主机连通性
- linux用于后台监控指定程序运行状况的脚本(如果程序死了则重启程序)
- linux脚本来进行网络连通性测试
- shell脚本之测试某网段内主机连通性
- ping命令_Linux ping 命令用法详解:测试主机之间网络的连通性
- 用于git测试的linux脚本
- Linux下创建用于并指定该用户的主目录和相关权限
- linux ping命令参数及用法详解--linux测试网络连通性命令
- Linux环境测试机器端口连通性
- Linux下设置脚本监控tomcat(经测试可用)
- 一个Linux中用于监控的简易shell脚本
- 批量登陆linux主机脚本
- linux脚本检测本机与指定IP段网络是否畅通
- linux脚本每隔几分钟ping指定ip如不通向指定手机发送短信
- linux指定定时脚本清理缓存车看内存使用情况
- Linux主机安全配置的几个脚本
- linux主机上webservice项目部署脚本
- shell脚本测试主机4个常见的网络服务是否开启
- 测试过程中常用的linux命令之【删除指定的文件行】