|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 Code:
mypid=`ps aux | awk '/test5/ && !/awk/ { print $2 }'`
echo PID is $mypidThe problem is the PID is not getting printed. But when i run the command directly in shell, the PID got printed. May i know where am going wrong in the script code? Thanks in advance. Amio |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
What kind of script is it? It's probably not that same as the shell you are working from. Your command wouldn't work in my console. But it did when I changed it to this. Code:
set a = `ps aux | awk '/test5/ && \!/awk/ {print $2}'`Last edited by Digby; 03-10-2009 at 11:54 AM.. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
Code:
# mypid=`ps aux | awk '/sshd/ && !/awk/ { print $2 }'`
# echo PID is $mypid
PID is 2077 2801 2806 2985 3410Read man ps for -w option. In the same time you should read man pgrep . |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AWK Output into a variable | mace_560 | Shell Programming and Scripting | 2 | 12-30-2008 03:58 AM |
| Put the output of grep in a variable | big123456 | Shell Programming and Scripting | 3 | 04-23-2008 11:40 AM |
| Set a variable from awk output | Cranie | UNIX for Dummies Questions & Answers | 3 | 10-11-2007 09:39 AM |
| storing output of awk in variable | mab_arif16 | Shell Programming and Scripting | 3 | 05-07-2006 06:15 PM |
| how to output awk to a variable | bashirpopal | UNIX for Dummies Questions & Answers | 4 | 04-02-2003 10:02 AM |
|
|