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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text string manipulation 1

Status
Not open for further replies.

trisco

MIS
Jan 3, 2001
44
0
0
US
I've searched for a similar solution, but can't seem to get what I'm looking for. It seems like there is a simple answer.

I'm putting together a korn shell script that monitors processes to determine if three different Oracle databases are up. I've got a variable that contains the processes I'm interested by using this command:

UP=`ps -ef |grep [p]mon |awk -F_ '{print $3}'`

$UP then can contain the following text:

systest uat train

These processes could be in any sequence and I need to verify that those three are each included in this resultant text string. If not, I need to identify which one or ones are missing, meaning they are not up.

Any guidance is appreciated.
 
Something like this...
Code:
#!/bin/ksh

export UP=`ps -ef |grep [p]mon |awk -F_ '{print $3}'`

[[ $UP = @(*systest*) ]] && print "systest is up" || print "systest is NOT up"
[[ $UP = @(*uat*) ]]     && print "uat is up"     || print "uat is NOT up"
[[ $UP = @(*train*) ]]   && print "train is up"   || print "train is NOT up"

# or, if you need to do something...

if [[ $UP = @(*systest*) ]]
then
    # Do something if it's up
else
    # Do something if it's NOT up
fi



 
A little more explanation, that's a pattern match that will find the string you are looking for no matter where it is in the string, so order doesn't matter.

See the man page for ksh for more information.


 
Thanks Sam. I'll use if-then-else form. Works as I desire.
 
I found this function on tek-tips and it works great.

function Is_Oracle_OK
{
if print "
select dummy||'OK' from dual;
" | sqlplus -s $APP_USERNAME/$APP_PASS@$SID | grep -q XOK
then return ${UP}
fi
return ${DOWN}
}
 
You could also use [tt]tnsping[/tt]. It's like a normal ping, but tests that the destination listener is up and running. It's a quick and easy way to test if your SQL*Net configuration is correct and someone's listening at the SID you are trying to reach. It should be part of any Oracle client or middleware software you may have installed.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top