Shell Programming Case: Modify the operation and maintenance script output effect

1, demand : the daily operation and maintenance check script dailymonitor.sh displaying server test results, which command

zabbix_get -s 192.168.111.21 -p 10050 -k "net.tcp.listen [3306] direct feedback value of 0 (abnormal) and 1 (normal), the display is not intuitive feel, consider shell scripts modified display, such as display : The Server 192.168.111.21 is ok!

 

2, the contents of the script:

#! /bin/sh

/usr/sbin/clock

Server21=`zabbix_get -s 192.168.109.21 -p 10050 -k "net.tcp.listen[3306]"`

Server20=`zabbix_get -s 192.168.109.20 -p 10050 -k "net.tcp.listen[80]"`

Server25=`zabbix_get -s 192.168.109.25 -p 10050 -k "net.tcp.listen[89]"`

function okbad {

if ( test $1 = 1 ) then               

# May also be expressed as if [$ 1 -eq 1]; then, note: When the "=" is used for assignments, both ends can not have spaces; "=" is used as a determination, there must be a space at both ends.

       echo $ {@: 2} is ok # Note:! as the second parameter spaces in an expression, must be $ {@: 2} expression of the way, otherwise, only to take the first space expression character before.

    else

       echo ${@:2} is bad !

    be

}

Server21_name="The Server 192.168.111.21 "

Server20_name="The Server 192.168.111.20 "

Server25_name="The Server 192.168.111.25 "

 

okbad $Server21 ${Server21_name}

okbad $Server20 ${Server20_name}

okbad $Server25 ${Server25_name}

 

3, operating results:

[root@localhost ~]# sh test.sh

January 25, 2019 Friday 19:54:09 -0.892307 seconds

The Server 192.168.111.21 is ok !

The Server 192.168.111.20 is ok !

The Server 192.168.111.25 is ok !

Guess you like

Origin www.cnblogs.com/sfccl/p/11246845.html