Intra-enterprise network segment detects how many hosts are alive1) byPingLifeorder to achieve
Ping-c 1-w 1 IP
- C: indicates the numberof times , 1 is 1
- W: represents deadline, time out , in seconds,1 for 1 seconds.
Note: a) If one goes to ping to wait for a long time, so the use of multi-threaded in the background to perform B) if not multi-threading, there is a problem is that when running for the loop CTRL +c can only stop the current loop of that, stop after the next for loop, can not be returned, but also to open a A terminal to kill the process of the script, inconvenient, this can be used trap to solve C) if the results of the key word is "OK", the best lang=en to English, or in the future, the problem is not good row wrong, or in English, so the interception of things also convenient and then according to the above three. Make the following script: ... The entry level is not counted.
2) Writing Scripts
[[email protected] scripts] #cat check_hosts.sh#!/bin/bash./etc/rc.d/init.d/functionsping= "Ping-w1-c 1" ip= " 192.168.0. "#trap" echo "Bye-bye"; exit "2for i in ' seq 1254 ' do {$ping ${ip}${i} >/dev/null if [$?-eq 0];then Actio n "${ip}${i} ...."/bin/true >>true.txt Else Action "${ip}${i} ..."/bin/false >>false.txt fi}& ;d One
3) Execute the script
[[email protected]] #sh check_hosts.sh
4) Check the results after the operation
[Email protected]]# cat True.txt
192.168.0.13 ... [OK]
192.168.0.1 ... [OK]
192.168.0.56 ... [OK]
192.168.0.10 ... [OK]
[[Email protected]]#
This article is from the "Linux Advanced Ops Road" blog, so be sure to keep this source http://yulianhui.blog.51cto.com/10829691/1725766
Intra-enterprise network segment detects how many hosts live--shell scripts