* Parameter transfer *

Source: Internet
Author: User

(1) assume that we have a function search in the script monitor that calls the searchlog function in the searchfile. Sh script, for example:

Extract part of searchfile. sh:

Searchlog ()
{
Local searchas = $1
Asinfo = ('getasinfo $1 ')
Local searchfile = $2
Local keyword = "$3"
Local linenum = 1000
If [! -Z $4]
Then
Linenum = $4
Fi

Searchcount = 'sh "$ sordir" remote-exec.sh "ssh $ {asinfo [1] }@$ {asinfo [0]} tail-$ linenum $ searchfile" $ {asinfo [2]} | grep "$ keyword" | WC-L | tail-1 | tr-d '\ n \ r''
If [$ searchcount-GT 0]
Then
Echo $ searchcount
Else
Echo 0
Fi
}

Searchlog "$1" "$2" "$3" "$4"

The function in monitor calls searchfile. sh:

Search ()
{
IP = $1
File = $2
Keyword = $3
Logfile = $4
Local productname = 'basename $2'
Searchcount = 'sh "$ sordir"/searchfile. Sh "$ IP" "$ file" "$ keyword" $5'
Echo "$ IP" 'date' "" $ keyword "===" $ searchcount >>$ logfile

If [$ searchcount-GT 0]
Then
:
#
Echo "$ IP" 'date' "" $ keyword "===" $ searchcount >>$ logfile ". error"
Echo "1"> $ logfile ". Alert"
Echo "0">/opt/Oracle/SOR/monitor/log/CPS. log. Alert
# Sh "$ sordir"/sender/mobilesender. Sh 'date "+ % m % d _ % H: % m" '"$ IP $ keyword = $ searchcount" $ telnum
Sh "$ sordir"/sender/mobilesender. Sh "$ IP $ productname $ keyword = $ searchcount" $ telnum
Fi

}

We can see that $5 is a null value, then the judgment statement will appear in the searchlog section of searchfile. Sh. If

If [! -Z $4]
Then
Linenum = $4
Fi

Then, the value of $4 in searchlog "$1" "$2" "$3" "$4" will use the default local linenum = 1000 ~

If $5 exists, we will pass the value of $4 to $ linenum.

(2) The following is just a part of the screenshot. The loop parameters are read from a configuration file:

Getip ()
{
CD $ {script_path}
Cat clear_log_example.conf | awk '{print $1}' | sort | uniq> ip. conf

}

Getip

While read IP
Do
Clear_control $ {IP}
Done<IP. conf

Here, we first use a function to obtain the IP configuration files of all hosts, and then read the IP addresses by one through a loop ~

(3) The following is a judgment statement. During script execution, there is usually only one parameter, and the script automatically enters a directory selection file;

If there are two parameters, the second parameter must be a file under that directory ~

If [$ #-EQ 2]
Then
Filename = $2
Else
If [$ #-ne 1]
Then
Echo "Usage: Sh $0 filepath"
Exit
Fi
Fi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.