Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Shell script applies "two" web service monitoring

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report