首页 电脑 电脑学堂 查看内容

linux 用于测试指定段的主机的连通性的脚本

2011-9-1 15:32 629 0

摘要: 题目如下: #!/bin/bash#the script's name is:*********use to test the host********* #the author is :R...
关键词: nbsp host echo state 语句 tmp NetIP PIP 知识点 DOWN

题目如下: #!/bin/bash#the script's name is:*********use to test the host********* #the author is :Ro#the version is :Ro-4-10let PIP=$1NetIP='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语句结合起来达到效果,还有排序等知识点,在 以后的网络中的运用也是很广泛的 本文出自 “IT梦-齐-分享” 博客,请务必保留此出处http://roqi410.blog.51cto.com/2186161/621983
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部