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