Get Pid from a command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get Pid from a command output
# 1  
Old 08-19-2010
Get Pid from a command output

pariosd -status

NodeName ID ROLE STATE PROTECTION
---------------------------------------------------------------------------
tn320_scm10 10 ACTIVE UP No Protection
tn320_scm11 11 UNKNOWN UNKNOWN


LocalApps PID STATE
-----------------------------------------------
HAM 3567641 RUNNING
SCM 3600404 RUNNING
ADF 3600411 RUNNING
EFM 3600412 RUNNING
WSM 3600413 RUNNING
AOP 3600414 RUNNING
INTDRV 3600415 RUNNING
CONFDPROXY 3600416 RUNNING
SYSCALL 3760161 RUNNING
LOGMGR 3760163 RUNNING
NODEMGR 3772452 RUNNING
ALARMMGR 3797029 RUNNING
ISSU 3797031 RUNNING
CHASMGR 3797032 RUNNING
ETHMGR 3797033 RUNNING
AOPMGR 3797034 RUNNING
ADFMGR 3797035 RUNNING
EFMMGR 3797036 RUNNING
OSCMGR 3797037 RUNNING
WSMMGR 3797038 RUNNING
SERVMGR 3829807 RUNNING
GMPLSNNI 3829808 RUNNING



I need to get the pid for each of the process shown above in sh script.
Please help me

Ravi

---------- Post updated at 04:33 PM ---------- Previous update was at 04:28 PM ----------

To be more specific,

After getting the PID of the process, i need to create a core dump for each of the process. how i can go thru a loop for collecting only the pid necessary

Thanks,
Ravi
# 2  
Old 08-19-2010
I'm not familiar with pariosd, but assuming it works like you've shown:
Code:
pariosd -status | tail -n +8 | awk '{print $2}'

tail -n +8 prints all lines after the first eight.
awk '{print $2}' prints the second field, the pid.

So you could loop through them like this:
Code:
for pid in $(pariosd -status | tail -n +8 | awk '{print $2}'); do
    echo $pid
done

# 3  
Old 08-19-2010
Code:
pariosd -status |awk 'NR>8 {print $2}'

For core dump, You need explain to us which type of PIDs you are interesting. Any rules to identify them?
# 4  
Old 08-19-2010
Hi, we Use QNX dumper process to create the core dump

#dumper -p <pid>

Thanks a lot , you gave me awesome solution.

I have one more question though, I have a file called apps.conf, and i need to parse and store the binary name in an array.
In the following, "execname = /PARIOS/sbin/scm", the executable binary name is scm...and so on.

Can you please give some solution...like how to store only binary names in an array.

# SCM Driver
[SCM]
execname = /PARIOS/sbin/scm
args = none
priority = mid
wait = no
critical = no
redundant = no
lock = no
dependency = none
debug_env = MEM_BAS

# ADF Driver
[ADF]
execname = /PARIOS/sbin/adf
args = none
priority = mid
wait = no
critical = no
redundant = no
lock = no
dependency = SCM
debug_env = MEM_BAS
# 5  
Old 08-19-2010
Try this one:
Code:
BINARIES=()
while read LINE; do
    BINARIES[${#BINARIES[@]}]=$LINE
done < <(sed -n '/^execname = /s/^execname = //p' apps.conf)

Code:
IFS=$'\n'
BINARIES=($(sed -n '/^execname = /s/^execname = //p' apps.conf))

bash 4.0
Code:
readarray -t BINARIES < <(sed -n '/^execname = /s/^execname = //p' apps.conf)


Last edited by konsolebox; 08-19-2010 at 11:20 PM.. Reason: forgot to specify the file
# 6  
Old 08-20-2010
Quote:
Originally Posted by hariprasad123
Hi, we Use QNX dumper process to create the core dump

#dumper -p <pid>

Thanks a lot , you gave me awesome solution.
Code:
pariosd -status |awk 'NR>8 {print $2}' |xargs dumper -p



---------- Post updated at 03:59 PM ---------- Previous update was at 03:52 PM ----------

Quote:
Originally Posted by hariprasad123

Can you please give some solution...like how to store only binary names in an array.
Code:
$ awk '/^execname/ {print $NF}' apps.conf
/PARIOS/sbin/scm
/PARIOS/sbin/adf

or only the name without full path
Code:
$ awk -F \/ '/^execname/ {print $NF}' apps.conf
scm
adf

To assign the O/P to array, you can refer konsolebox's
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

2. Shell Programming and Scripting

How to find the corresponding command for a existing PID?

Hi All, A process completed already and I have the PID. I want to know the which command used for this PID. 'ps' command and '/proc' folder having the list current process only. Is there a way to search completed process PID? Thanks, Manimuthu (5 Replies)
Discussion started by: k_manimuthu
5 Replies

3. UNIX for Dummies Questions & Answers

Determine uniqueness of pid to name output files

Hi, We've a process on AIX UNIX server which is executed by multiple uses during a day. I wish to create a log file for every time the process is executed. I wish to know how unique are PID(s) on AIX UNIX servers if I were to name the log files with <date> and <PID>? E.g. If I create my... (1 Reply)
Discussion started by: vkumbhakarna
1 Replies

4. UNIX for Dummies Questions & Answers

UNIX command to get inode's tid and pid

Hi everyone, I am new here in www.unix.com, i found this site because I am looking for an answer to this problem of mine. I need to know a UNIX command to display an inode's thread id and process id. Hope someone can help me on this. Thanks :D (8 Replies)
Discussion started by: rodkun
8 Replies

5. AIX

kill -3 <PID> ... where the output file goes?

Hi all, I am generating the coredump of my JBoss, and by default it puts it in to a particular directory. i.e. JBOSS_HOME/. I would like this output file to be created, lets say in /tmp/dump/. I tried the following: kill -3 9404940>/tmp/dump/out.txt But it created... (3 Replies)
Discussion started by: haroon_a
3 Replies

6. Shell Programming and Scripting

output nohup file containg the PID

Hi to everybody. Is it possible to nohup a process and redirect the output to a file containing the PID? E.g. if nohup filename > out.nohup associate the PID=8074 to filename, is it possible to call the output file something like out_8074.nohup instead of out.nohup? By this way it would... (0 Replies)
Discussion started by: plsrn
0 Replies

7. Shell Programming and Scripting

Output of ps + awk in a variable to get PID

Hi All, I am getting the PID of a process using its name using the following command in a script mypid=`ps aux | awk '/test5/ && !/awk/ { print $2 }'` echo PID is $mypid The problem is the PID is not getting printed. But when i run the command directly in shell, the PID got printed. ... (2 Replies)
Discussion started by: amio
2 Replies

8. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

9. UNIX for Advanced & Expert Users

To get PID of a command passed to a secondary system

Hi Reqmt: I am working on Sys 1 and passes a command to Sys2 using a utility which has ssh coded in it. Is there any way to get the process id of the command in Sys 2 from my Sys1 ? Note: The utility is not editable, so you cannot get it through it and I am not logged in in Sys2. Thanks... (2 Replies)
Discussion started by: anu_math9
2 Replies

10. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies
Login or Register to Ask a Question