(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