改脚本查看哪些ip被占用。

#!/bin/bash

for i in {1..10}   //赋予i变量1-10

do   //干什么

ping -c1 -w1 192.168.7.$i &> /dev/null   //ping 192.168.7.网段 每个ip1次 显示1行全输出到无底洞

if [ $? -eq 0 ]; //返回值是否为0

then   //如果返回值为0则做下面的输出

echo station$i is up!

else   //否则

echo station$i is down!  //输出这步

fi   done

赋予该脚本可执行权限: chmod +x ipadd.sh

执行该脚本:

[root@localhost shellscripts]# ipadd.sh

station1 is up!

station2 is down!

station3 is up!

station4 is down!

station5 is down!

station6 is down!

station7 is down!

station8 is down!

station9 is down!

station10 is down!

===========================

[root@localhost shellscripts]# ping 192.168.7.3

PING 192.168.7.3 (192.168.7.3) 56(84) bytes of data. 64 bytes from 192.168.7.3:

icmp_seq=1 ttl=64 time=0.043 ms 64 bytes from 192.168.7.3:

icmp_seq=2 ttl=64 time=0.040 ms ^C --- 192.168.7.3

ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1791ms rtt min/avg/max/mdev = 0.040/0.041/0.043/0.006 ms

[root@localhost shellscripts]# echo $?   //ping通返回值为0

0 ==============================

[root@localhost shellscripts]# ping 192.168.7.4

PING 192.168.7.4 (192.168.7.4) 56(84) bytes of data.

From 192.168.7.3 icmp_seq=1 Destination Host Unreachable From 192.168.7.3

icmp_seq=2 Destination Host Unreachable From 192.168.7.3

icmp_seq=3 Destination Host Unreachable ^C --- 192.168.7.4

ping statistics --- 5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4084ms pipe 3

[root@localhost shellscripts]# echo $? 1     //ping不通返回值不为0

《通过脚本查看哪些ip被占用》shell笔记的更多相关文章

  1. bash shell笔记1 脚本基础知识

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://twentyfour.blog.51cto.com/945260/505644 * ...

  2. Bash shell 笔记总结(一) 转自http://www.bubuko.com/infodetail-509992.html,谢谢原作者

    本文是上课笔记总结,涉及细节知识点会在以后文章说明! bash脚本编程: 脚本程序:解释器解释执行: shell: 交互式接口:编程环境: shell: 能够提供一些内部命令,并且能通过PATH环境变 ...

  3. Java中执行shell笔记

    在java中执行shell有好几种方式:第一种(exec)方式一 public static synchronized void runshell2() {    File superuser = n ...

  4. shell笔记

    shell:俗称操作系统的"外壳",就是命令解释程序.     是用户与Linux内核之间的接口.     是负责与用户交互,分析.执行用户输入的命令,并给出结果或出错提示.    ...

  5. shell笔记-local、export用法 、declare、set

    local一般用于局部变量声明,多在在函数内部使用.     1.    Shell脚本中定义的变量是global的,其作用域从被定义的地方开始,到shell结束或被显示删除的地方为止.     2. ...

  6. shell 笔记

    shell 笔记 通配符 没有 '.' [Aa] 表示 A 或者 a ? 表示任意字符 * 表示任意字符串 IFS data='name, sex, rollno, location' oldIFS= ...

  7. shell笔记(基本知识)

    一.编写第一个shell程序 实例1: [程序] #!/bin/sh echo "hello word !" [运行]

  8. shell笔记-local、export用法

    local一般用于局部变量声明,多在在函数内部使用.    1.    Shell脚本中定义的变量是global的,其作用域从被定义的地方开始,到shell结束或被显示删除的地方为止.    2.   ...

  9. 【转】Linux shell笔记

    由于工作的需要,越来越多的接触到linux系统.最近看了<Linux与Unix Shell>这本书,安装书的章节整理了一些自己认为比较重要的命令,方便以后查阅. No.001 文件安全与权 ...

  10. shell笔记-常用

    shell提取文件名: http://blog.csdn.net/u011544778/article/details/50773053 一.使用${} 1.${var##*/}该命令的作用是去掉变量 ...

随机推荐

  1. SimpleDateFormat使用详解及与毫秒的相互转换

    1. SimpleDateFormat使用详解 public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方 ...

  2. 解决vim中鼠标右键无法复制的问题

    转:http://www.cnblogs.com/jianyungsun/archive/2011/03/19/1988855.html 这是我的vim配置文件:jeffy-vim-v2.4.tar ...

  3. LeetCode25 Reverse Nodes in k-Group

    题意: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list ...

  4. LeetCode23 Merge k Sorted Lists

    题意: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexit ...

  5. redis 简介

    Redis是一种高级key-value数据库.它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富.有字符串,链表,集 合和有序集合.支持在服务器端计算集合的并,交和补集(diff ...

  6. solr查询在solrconfig.xml中的配置

    <requestHandler name="/select" class="solr.SearchHandler"> <lst name=&q ...

  7. ios UIWebView截获html并修改便签内容(转载)

    ios UIWebView截获html并修改便签内容 博客分类: iphone开发iphone开发phoneGap uiwebviewstringByEvaluatingJavaScriptFromS ...

  8. 机房收费系统之uml图——初版

    说起uml图,在我心中最难的当属类图无疑.虽然敲了三层的小例子,但真正让把三层和uml图结合起来,并且还要考虑设计模式的时候,总是让人有一种无从下手的感觉,不过还好,通过这半个多月的思考与探索(竟然用 ...

  9. PHP动态函数

    header('Content-type:text/html;Charset=utf8'); function welcome(){ echo 'Welcome to you.'; } functio ...

  10. Ajax中get提交和post提交的区别

    $.post("HandlerLiuYan.ashx", { leixing: leixing, danwei: danwei, liuyan: liuyan, name: nam ...