Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Other *NIX Forums > AIX
User Name
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.


  Search this Thread
Old 06-15-2011, 10:49 AM   #1
Registered: Aug 2001
Location: Magic City, USA
Distribution: Ubuntu
Posts: 73

Rep: Reputation: 15
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.

Old 06-15-2011, 11:00 AM   #2
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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.
1 members found this post helpful.
Old 06-16-2011, 03:44 PM   #3
Registered: Aug 2001
Location: Magic City, USA
Distribution: Ubuntu
Posts: 73

Original Poster
Rep: Reputation: 15
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}'`


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to switch to command line from GUI using keyboard shortcut tj_linux Linux - Newbie 16 05-16-2010 07:29 AM
LXer: Switch to the Command Line, Part 1. LXer Syndicated Linux News 1 05-13-2009 04:07 AM
Help Please!! -- need to find command that will switch you back to your previous CWD Tron55555 Linux - General 2 05-15-2008 10:35 PM
How to switch an application from one desktop to another using command line demianxyz Linux - Software 2 10-15-2006 06:36 PM
How switch from x-window to the command line backpacker Linux - Newbie 1 06-09-2005 03:56 AM > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 12:23 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration