Shell script ping test (Code instance), shellping

Source: Internet
Author: User

Shell script ping test (Code instance), shellping
Shell script ping Test

Principle: use shell scripts to execute a ping command.

1) The destination_ip variable is the IP address of the target host. 2) The-c1 parameter after ping indicates the maximum number of test packets sent from the host to the target host. 3) &> for redirection 4) create a file, vi pingtest. sh, and add the following code 1/2/3:

#! /Bin/bashdestination_ip = 192.168.109.2if ping-c1 $ destination_ip &>/dev/nullthen echo "$ destinaion_ip is online." elseecho "$ destination_ip is offline." fi

2. Code 2

#! /Bin/bash $ destination_ipread-p "please inpur ip:" destination_ipif ping-c1 $ destination_ip &>/test.txt then echo "$ destination_ip is online. "else echo" $ destination_ip is offline. "fi

3. Code 3

#! /Bin/basync ping-c1 $1 &>/test.txt then echo "$1 is online." else echo "$1 is offline." fi

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.