Shell script applies "two" web service monitoring
The requirement is to remotely monitor whether the web is normal.
1) use parameter transfer method
2) the judgment parameter is correct.
3) output prompt
Script practice
#! / bin/sh
# referencing system functions
[- f / etc/init.d/functions] & &. / etc/init.d/functions
# determine whether the input parameters are correct
Usage () {
Echo "USAGE:$0 url"
Exit 1
}
# define variables
RETVAL=0
FunCheckUrl () {
Wget-T 10-- spider-t 2 $1 > / dev/null 2 > & 1 # & > / dev/null
RETVAL=$?
If [$RETVAL-eq 0]; then
Action "$1 url" / bin/true
Else
Action "$1 url" / bin/false
Fi
Return $RETVAL
}
Main () {
If [$#-ne 1]; then
Usage
Fi
FunCheckUrl $1
RETVAL=$?
Return $RETVAL
}
Main $*
# script name: test.sh input parameters: 1, 2, 3
# after running test.sh 1, 2, 3
# $* is "1 2 3" (enclosed in quotation marks)
# $@ is "1"2"3" (wrapped separately)
# $# is 3 (number of parameters)
# 2 > / dev/null error orientation null
# > / dev/null 2 > & 1 is equal & > / dev/null both correct and wrong are oriented null