Need help with ksh script

Hi,

I need to use ksh script to do following

/usr/ucb/ps -augxww | grep  ALGX_DEV__AS2 | awk '{print $14}'

if above ps command return nothing
then
run this:

/opt/OV/bin/OpC/opcmsg severity=critical application=SF_Symphony object=Script msg_text="Process not running" msg_grp=ALGX_DEV

and if ps command return successful then don't output anything and wait.

So this is what i have done and I am new to scripting so please bare with me if there are mistakes below:

#!/usr/bin/ksh
PS=`/usr/ucb/ps -augxww | grep  ALGX_DEV__AS2 | awk '{print $14}'`
        if [$PS -lt 1]
         then
          /opt/OV/bin/OpC/opcmsg severity=normal application=Test object=Script msg_text="Process not running" msg_grp=Test
  fi

So when i run above script manually i get this error:

./javaproc.sh[3]: test: ] missing

Thanks for your help.
Desi

It should be if

1 Like

Ok so space was the issue? I added the space between brackets and now i get this error

#!/usr/bin/ksh
PS=`/usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | awk '{print $14}'`
        if [ $PS -lt 1 ]
         then
/opt/OV/bin/OpC/opcmsg severity=normal application=Test object=Script msg_text="Process not running" msg_grp=Test
  fi

./javaproc.sh[3]: test: argument expected

for debug i did

# sh -x ./javaproc.sh
+ /usr/ucb/ps -augxww 
+ awk {print $14} 
+ grep PLGX_Prod__MgdSvr2 
PS=
+ [ -lt 1 ] 
./javaproc.sh: test: argument expected

Please post the output from:

/usr/ucb/ps -augxww | grep ALGX_DEV__AS2

/usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | grep -v "grep"

/usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | awk '{print $14}'

/usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | grep -v "grep" | awk '{print $14}'

PS I have no idea how $PS could contain a number, hence this post.

Here it is:
I only want to run opcmsg when this process goes down.

-Dweblogic.Name=ALGX_DEV__AS2
# /usr/ucb/ps -augxww | grep ALGX_DEV__AS2
ecomadm  28706  0.1  0.81522040509120 ?        S 02:23:55  6:10 /appbin/sf/Oracle/Fiddlefare/11.1.1.5/jdk160_24/bin/java -server -Xms256m -Xmx512m -XX:MaxPermSize=128m -Dweblogic.Name=ALGX_DEV__AS2 <deleted>
[1] +  Done                    /usr/ucb/ps -augxww | grep ALGX_DEV__AS2



# /usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | grep -v "grep"
ecomadm  28706  0.1  0.81522040509120 ?        S 02:23:55  6:10 /appbin/sf/Oracle/Fiddlefare/11.1.1.5/jdk160_24/bin/java -server -Xms256m -Xmx512m -XX:MaxPermSize=128m -Dweblogic.Name=ALGX_DEV__AS2 <deleted>
[1] +  Done                    /usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | grep -v "grep"



# /usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | awk '{print $14}'
-Dweblogic.Name=ALGX_DEV__AS2
[1] +  Done                    /usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | awk '{print $14}'



# /usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | grep -v "grep" | awk '{print $14}'
-Dweblogic.Name=ALGX_DEV__AS2
[1] +  Done                    /usr/ucb/ps -augxww | grep ALGX_DEV__AS2 | grep -v "grep" | awk '{print $14}'

Okay, the value of $14 is never a number. Therefore $PS is never a number.
Perhaps you need to count the hits? The awk is not necessary.

#!/usr/bin/ksh
PS=`/usr/ucb/ps -augxww | grep "ALGX_DEV__AS2" | grep -v "grep" |wc -l`
if [ ${PS} -eq 0 ]
then
         /opt/OV/bin/OpC/opcmsg severity=normal application=Test object=Script msg_text="Process not running" msg_grp=Test
fi

Hmm. severity=normal ? That would reset the Openview alert after a previous failure.

Mystified. The Done lines suggest that you are putting a every command into background with an & character at the end of the line or backgrounding commands with some other method like ^Z . Very weird.

Word of warning. On a heavily loaded system ps can miss processes. It is safer to react to three consecutive failures rather than just the one. At least repeat the check at the start of the restart script and abort if the process is in fact still running.

ok i configure the script as you suggested and now output is clean but no message comes in from opcmsg?
severity was for testing only. change it to warning.

here is debug

# sh -x ./javaproc.sh
+ /usr/ucb/ps -augxww
+ grep PLGX_Prod__MgdSvr2
+ wc -l
+ grep -v grep
PS= 0
+ [ 0 -eq 1 ]

Please review the exact script you ran. Big hint, the Shell execution trace shows a comparison with the value 1 not the value 0 .
If there is still a problem, please post the script.

Ps. I really appreciate you posting the Shell execution trace. Many posters could learn from your example.

1 Like

ok i got it working. had to change 1 to 0

I like your idea of doing 3 checks for ps command.

I am new to this scripting, can you show me how to do counters?

thanks

Bedtime. I'm in UK timezone.
Anybody awake who can answer this one?

No rush.. whenever you have time...
you provided great help here.
Thanks a bunch..