Operating System - HP-UX
1748264 Members
3941 Online
108760 Solutions
New Discussion юеВ

ps command in ksh script fails

 
Ratzie
Super Advisor

ps command in ksh script fails

For the life of me, I have no idea why this keeps failing, I have tried multiple different ways to get this to work. I run this as a test, no problem it works, as soon as I run in cron it fails with:
ps: option requires an argument -- u
usage: ps [ -aAdeflcjLPyZ ] [ -o format ] [ -t termlist ]

(( count=40 ))
while ((count -=1))
do
MQSTAT=`ps -ef |grep amqzxma0 |grep -v grep`
if [[ -z $MQSTAT ]]
then
break
fi
sleep 30
echo $MQSTAT >>$SSLOG
done


2 REPLIES 2
Dennis Handly
Acclaimed Contributor

Re: ps command in ksh script fails

I just see "ps -ef", no -u at all.
You may want to add "set -x" to your shell script to see what is executing.
Bill Hassell
Honored Contributor

Re: ps command in ksh script fails

> usage: ps [ -aAdeflcjLPyZ ] [ -o format ] [ -t termlist ]

This isn't an HP-UX ps option list. Are you running on HP-UX or are you using a non-standard ps.

Note that ps piped to grep will be full of problems because grep won't look in just one part of the line. -u is the user option in HP-UX so there is no need to use "grep something" or "grep -v grep" at all. Simply run the command:

ps -f -u someuser

ps will perform an exact match on the user field. This will show a title line even with no matches, so you can use the -o option to pick the fields you want to use:

UNIX95=1 ps -u someuser -o pid= -o ppid= -o ruser -o args

UNIX95=1 is required for HP-UX ps to use the -o option. NOTE: not much of this applies to non-HP-UX systems.


Bill Hassell, sysadmin