Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the process id via KSH or AWK 1

Status
Not open for further replies.

rousse

Programmer
Sep 24, 2003
12
US
Hello,

I want to check with a ksh script if another process is running and get the process id, too. Also, I am able to get the following line:

userid 2345 1 0 13:58:52 pts/tg 0:00 abcd -a devl -f /home/cfg/abcd.cfg

How can I retrieve the pid value - 2345 - and assign it to a local variable? I tried this unsuccessfully:

TARGET_PID=`ps -ef | grep 'abcd -a' | grep -v grep | cut -d" " -f3`
or...
TARGET_PID=`ps -ef | grep 'abcd -a' | grep -v grep | awk '{print $2}'`

Any ideas? Thank you.


 
And what about this ?
Code:
TARGET_PID=`ps -ef | awk '/abcd[ \t]*-a/{print $2}'`


Hope This Help
PH.
 
Dear PHV,
It works!!! Thanks a lot!
PP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top