局域网中分了很多网段,而IP地址使用情况也未知,前期也没有规划和记录,当新的主机需要使用固定IP的时候,能否第一时间知道哪个IP空闲就显得很重要了,如果一个一个去ping的话太浪费时间. 这里分享一个shell脚本检测当前哪些IP在用和不在用. 脚本如下: #!/bin/bash #先生成一个网段的IP文本 ippre="192.168.10." for i in {1..254} do echo "${ippre}$i" >>ip.txt done #
方法1: if grep -qs '/mnt/foo' /proc/mounts; then echo "It's mounted." else echo "It's not mounted." fi 方法2: if mountpoint -q /mnt/foo then echo "mounted" else echo "not mounted" fi
<1> d211 admin # for i in {3..254} ; do ping -c 1 192.168.1.$i &>/dev/null && echo 192.168.1.$i is alive ;done192.168.1.5 is alive192.168.1.7 is alive <2> fping -a -g 192.168.5.1 192.168.5.177 -s -n >lele.txt -a Show system
Linux shell脚本判断网络畅通 介绍 在编写shell脚本时,有的功能需要确保服务器网络是可以上网才可以往下执行,那么此时就需要有个函数来判断服务器网络状态 我们可以通过curl来访问 www.baidu.com,从而判断服务器网络状态是否可以畅通的 网络状态判断 #!/bin/bash #检测网络链接畅通 function network() { #超时时间 local timeout=1 #目标网站 local target=www.baidu.com #获取响应状态码 local