Linux command: AUTO PING

Source: Internet
Author: User

Implemented using While,until and for (two forms) loops respectively.

Requirements: Test the host online via the ping command,
If online, "IP is Up", where the IP is to be replaced with a real IP address, and displayed in green;
If you are not on the line, the IP is down, where the IP is changed to a real IP address and displayed in red;


#!/bin/bash
#
For I in {200..201}; Do
Ping-c 1-w 1 10.109.131. $I &>/dev/null
[$?-eq 0] && echo-e "\033[36m110.109.131. $I is up\033[0m" | | Echo-e "\033[35m110.109.131. $I is down\033[0m"
Done

DECLARE j=215
While [$J-lt 217];d O
Ping-c 1-w 1 10.109.131. $J &>/dev/null
Pp=$?
[$PP-eq 0] && echo "110.109.131 $J is up" | | echo "110.109.131. $J is Down"
Let J + +
Done

DECLARE k=220
Until [$K-gt 222];d o
Ping-c 1-w 1 110.109.132. $K &>/dev/null
P3=$?
[$P 3-eq 0] && echo-e "\033[36m110.109.132. $K is up\033[0m" | | Echo-e "\033[35m110.109.132. $K is down\033[0m"
Let k++
Done


[Email protected] ~]#./ping.sh
110.109.131.200 is up
110.109.131.201 is up
110.109.131.215 is down
110.109.131.216 is down
110.109.132.220 is up
110.109.132.221 is down
110.109.132.222 is up

Linux command: AUTO PING

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.