Operating System - HP-UX
1825759 Members
2141 Online
109687 Solutions
New Discussion

Does ps command capture process name with spacing

 
Loo Man Shong_1
Advisor

Does ps command capture process name with spacing

I'm writing a shell script to monitor the process called 'remsh AUCSUBH1_p startfp dbs 7500' running on hpux 10.20 and using sendmail command to send the email to the administrator once the system detected the process is not running. The command that I used is
ps -u taucadm | grep 'remsh AUCSUBH1_p startfp dbs 7500' | grep -v grep

and it doesn't seem to be running but if I replace the process 'remsh AUCSUBH1_p startfp dbs 7500' with sendmail process, it work fine. Any idea? is it because of the ps command cannot capture process name with spacing?

Here is the shell script that I used:

startfp_dbs_7500=
startfp_dbs_7500=`ps -u taucadm | grep 'remsh AUCSUBH1_p startfp dbs 7500' | grep -v grep`
if [ -z "$startfp_dbs_7500" ]
then
echo "startfp_dbs_7500 process not running"| mailx -s "Notification Message" ms_loo@yahoo.com

fi

Thanks

Rgds
Loo
6 REPLIES 6
Niraj Kumar Verma
Trusted Contributor

Re: Does ps command capture process name with spacing

Hey !!

try

startfp_dbs_7500=
startfp_dbs_7500=`ps -u taucadm | grep 'remsh AUCSUBH1_p startfp dbs 7500' | grep -v grep`
if [ "_$startfp_dbs_7500" = "_$startfp_dbs_7500" ]
then
echo "startfp_dbs_7500 process not running"| mailx -s "Notification Message" ms_loo@yahoo.com

fi

Niraj.Verma@philips.com
Loo Man Shong_1
Advisor

Re: Does ps command capture process name with spacing

Dear All,

Still the same, cannot capture the process name with spacing. Any idea?


Thanks

Rgds
Loo
john korterman
Honored Contributor

Re: Does ps command capture process name with spacing

Hi,
try this (with space after equal sign):
# UNIX95= ps -u taucadm -eo args | grep "remsh AUCSUBH1_p startfp dbs 750[0]"

regards,
John K.
it would be nice if you always got a second chance
Adam J Markiewicz
Trusted Contributor

Re: Does ps command capture process name with spacing

Hi

It is not problem with 'spaces in names', as in both cases you don't use names with spaces.

The command name is remsh and as this it is showed by 'ps'.

What do you need is to get commandline, instead of simple command name. John suggests option 'ps -o args', however it is not accepted on my machine, so it can be also on yours.

Use 'ps -f' instead. It replaces command name with command line and as far as I know is honored by every existing 'ps' command.

So complete would be: 'ps -fu taucadm'

Good luck

Adam
I do everything perfectly, except from my mistakes
Jean-Louis Phelix
Honored Contributor

Re: Does ps command capture process name with spacing

Hi,

Both John and Adam are right ... A simple ps will only display the program name. If you have a look at the 'exec' man page, you will see that a 'standard' call contains :

exec...(file, arg0, arg1, ...)

with args either as a list or as pointer to a list. In your case, 'ps' without option only displays arg0 (the executable file), while the option '-f' (and also the option -o args if yoy have respected exactly what John said, including space after UNIX95=) while also display arguments (arg1, ...)

But I also wanted to tell you that it's a good practice to assign points to people helping you), for example Adam and John. I can read :

This member has assigned points to 0 of 10 responses to his/her questions.

Regards.
It works for me (© Bill McNAMARA ...)
T G Manikandan
Honored Contributor

Re: Does ps command capture process name with spacing

x=`UNIX95= ps -e -o comm|grep 'remsh AUCSUBH1_p startfp dbs 7500'|grep -v grep|wc -l`
if test $x=1
then
echo "startfp_dbs_7500 process not running"| mailx -s "Notification
else
echo Not running
fi


Thanks