Use shell script to ping the name of the corresponding IP (recommended) _linux shell

Source: Internet
Author: User
Tags arithmetic ping network
#!/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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.