A friend mentioned a demand, there are a number of applications of the host need to check whether the network is normal, of course, many methods, such as deployment and saltstack, directly check whether minions online, or you can use Python to get a simple script directly ping. Anyway, a lot of methods, this time I intend to use the shell to achieve a simple, of course, this is just a simple demo, you can add a lot of content, such as writing to log, can also be in-depth, get the host name, daily scheduled to send reports and so on. This is primarily a simple exercise for shell programming, a function call.
Test as follows
#!/bin/sh function demo_ping () {ping-c 1 172.16.1.${1} >/dev/null 2>&1 if [$? = = 0];then return 0 Else Return 1 fi}for i in ' seq 1 254 ';d o demo_ping $i if [$? = 0];then echo "Server of 172.16.1.${i} is on Lin E "Else echo" server of 172.16.1.${i} is offline "Fidone
Results
[Email protected]_slliang ~]# SH ping.sh
Server 172.16.1.1 is on line
Server 172.16.1.2 is offline
Server 172.16.1.3 is on line
Server 172.16.1.4 is on line
Server 172.16.1.5 is offline
This article is from "It small Angry green" blog, please make sure to keep this source http://slliang.blog.51cto.com/6959776/1897449
Linux Bulk test Online host