#!/bin/bash
a= (Dick Harry Zhao Liu) for
i ' {0..3}
do
if Ping-c 1 192.168.1. $ ((${i}+1)) >dev/null 2>& 1;then
Echo $ ((${i}+1)) "${a[${i}]}" online "
else
Echo $ ((${i}+1))" "" ${a[${i}]} "offline"
fi
Done
This string of shell code implements the ping of the name of the IP address that is used for the online
The knowledge points involved are variables, arrays, loops, if judgments, arithmetic operations.
Loop here and if I don't talk much!
The main applications are variables, arrays, and arithmetic operations.
First I define an array variable of four names, and then define a loop body loop from 0 to 3, which is the corresponding a[0 in the array when applied below. A[3] Four person's name.
Then start if judgment, ping 192.168.1.0 the corresponding ordinal number 1 in this network segment. 4, correspond to different people and because the number in the loop starts at 0 and the ping network address needs to start at 1, it's used in the shell. The arithmetic Operation "$ (())" in which I will loop the body is a number of +1 so the ping is actually ping 192.168.1.0 +1.. 192.168.1.3+1
The following is simple to show the host number 1..4 and host number of the name.
The above is a small series to introduce the use of shell script to achieve ping corresponding to the IP of the name, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!