Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Korn Shell script need to add another search criteria

Status
Not open for further replies.

jlaw10

Technical User
Jul 28, 2005
54
US
I created the following script that searches the 'RMAN-00571' text in our RMAN logs and writes the results to a logfile and then will email this log to our DBAs. I want to add a search that will verify that the "Recovery Manager complete" text also exists in all the logfiles. If this string does not exist then I also want to write the filename of the file that does not include this text to the RMAN_error.log

Note: The "Recovery Manager complete" verifies that the backup job finished. So if it did not finish, the DBAs need to be alerted.

#!/bin/ksh
#
# Report RMAN errors and send email to DBA - JAO 10/31/2005
#

export DBALIST="xyz@hotmail.com,xyz2@hotmail.com"
export date=`date`

grep -i "RMAN-00571" /u002/LOG/*/* > u002/LOG/RMAN_error.log

mailx -s "${date} RMAN errors" $DBALIST < /u002/LOG/RMAN_error.log
 
Add the following line before the mailx:
grep -ic "Recovery Manager complete" /u002/LOG/*/* | sed -n 's!:0$!!p' >> u002/LOG/RMAN_error.log

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks that worked! Preciate it!

One more thing - what does the " sed -n 's!:0$!!p' " do?
 
man sed

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
jlaw,

The sed command will only print the lines that end with :0, but first it will strip the :0 out of the line.

Maybe this will help:

Code:
$ echo test:0 | sed -n 's/:0$//p'
test
$ echo test:03 | sed -n 's/:0$//p'
$ echo test:0test | sed -n 's/:0$//p'
$ echo :0test | sed -n 's/:0$//p'
$ echo :0 | sed -n 's/:0$//p'

$
(Noticed I converted the ! to / - sed isn't picky. We could also use |,#,etc.)

The -n switch tells sed not to print out any output that it normally would (the opposite switch is -e).

The s at the beginning tells sed this will be a substitution.

The :0$ inside the first set of / / tells sed to look for a :0 at the end of a line ($ means the end, ^ means the front).

The // is the part where you can specify what to substitute - in this case it is nothing - you are effectively removing what you told sed to search for. If the line was sed -n 's/:0$/:1/p' then it would replace :0 with :1

The p at the end tells sed to only print the substituted text if a substitution was made.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top