Shell script:
A text file that contains some commands or declarations and conforms to a certain format
Format requirements: First line shebang mechanism
#!/bin/bash
#!/usr/bin/python
#!/usr/bin/perl
The purpose of the shell script is:
? Automation common Commands
? perform system administration and troubleshooting
? Create a simple application
? working with text or files
First step: Use a text editor to create a text file
? The first line must include the shell declaration sequence: #!
#!/bin/bash
? Add comments
Comments start with #
? Step two: Run the script
Give execute permission to specify the absolute or relative path of the script on the command line
Run the interpreter directly and run the script as a parameter of the interpreter program.
Next I write a script called hostping.sh to detect if an IP address is connected to the host
#/bin/bash
Read-p "Please input ipaddress!:" IP//Note Enter an IP address for the parameter
[[! $ip =~ ([0-9]|[ 1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]) \.) {3} ([0-9]| [1-9] [0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]]]//Notes [[]] two brackets are the exact conditions used to support the decision of the IP address after the command of the extended expression, because we know that the IP address format is XXX.XXX.XXX.XXX The maximum can not exceed 255 so we match 0-99,100-199,200-249,250-255 the number of paragraphs, so that we can do not less than the IP address.
&& echo "Please enter your IP address!" && exit 20//If the IP address entered is not the correct format of the IP address, we will directly output enter a correct IP address and return a 20 value.
' Ping $ip-w1-c1 &>/dev/null ' && echo ' This IP address can accessed! ' | | echo "This IP address was not accessed!"
Apply IP This variable to detect whether the IP address is connected, if connected to the output of connected message, otherwise is not connected.
Shell script detects IP address