-   AIX (
-   -   find command line switch value (

Cpare 06-15-2011 10:49 AM

find command line switch value
I am creating a script to stop a service thats been running for too long, in this case however we want to call the vendors .sh which allows the appliction to shutdown gracefully (so a "kill-9" just isn't going to cut it).

To call the vendors .sh I need to pass it the "Name" of the server service (specified using the -name command line switch when starting the daemon). This value is visible when you do a "ps -ef", however it can fall in random places.

For example:


boadmin 155984 328134  0 07:48:48      -  2:40 /opt/apps/busobj/bobj/bobje/enterprise120//aix_rs6000/WIReportServer -loggingPath /opt/apps/busobj/bobj/bobje/logging/ -fg -restart -name SIA_oianp140.WebIntelligenceProcessingServer5 -pidfile /opt/apps/busobj/bobj/bobje/serverpids/ -ns oianp007:6400 -ns oianp007:6400
Any suggestions how I can "Find" the value after the "-name" command line option? do I need to throw the ps-ef results into an array, and then loop through it looking for the "-name" so i can take the next item in the array? That seems too complex IMHO, so I thought I would ask before trying to reinvent the wheel.


colucix 06-15-2011 11:00 AM

You can try with awk:

ps -C WIReportServer -o args | awk 'BEGIN{RS=" "}/-name/{getline; print}'
not sure if the ps command on AIX accepts the option -o args, but you can put your own ps command here to extract the wanted line. The awk part puts all the space-separated fields on different lines and prints out the line that immediately follows the -name option.

Cpare 06-16-2011 03:44 PM

Thanks for this suggestion, I ended up with the following line in my .sh

strBOBJName=`ps -ef |grep ${arrDaemonPIDList[i]} | awk 'BEGIN{RS=" "}/-name/{getline; print}'`

All times are GMT -5. The time now is 05:45 PM.