You are not logged in.
Hello,
Here is my little script.
ps -eo comm,pid,args | awk '$1 == "java" { print $2 }'
It works well. However, in addition to comparing $1 to the name of the process, I'd like to search args and make sure that it does not have certain values (say "efox".)
This is what I've tried so far.
ps -eo comm,pid,args | awk '(($1 == "java") && (!match($3, "amboo"))) { print $2 $1 }'
But that does not give me _any_ PIDs now and there should be 3 (the previous script gives me 4.)
Any ideas?
Last edited by publicus (2014-05-07 19:44:47)
Offline
Tried this, also did not work.
ps -eo comm,pid,args | awk '(($1 == "java") && (index($3, "amboo")) == 0) { print $2 }'
21950
21981
22038
22116
2116 is not supposed to be listed there.
Last edited by publicus (2014-05-07 19:13:14)
Offline
Ok, this is what I needed to do:
$ ps -eo comm,pid,args | awk '(($1 == "java") && ((index($4, "amboo")) == 0)) { print $2 }'
I'm a n00b to awk, but -- correct me if I'm wrong -- the individual pieces of information are delimited by spaces and the args that I was sifting through was something like this "/some/folder/java -Dstuff", the space was throwing me off.
Offline
The default field separator is a space. You can change that using -F.
You could also use something like this (just guessing what your input looks like):
ps -eo comm,pid,args | awk '/java/ && !/amboo/ { print $2 }'
Offline
The default field separator is a space. You can change that using -F.
You could also use something like this (just guessing what your input looks like):
ps -eo comm,pid,args | awk '/java/ && !/amboo/ { print $2 }'
That code is obsolete now, the project has taken a different turn and I have a solution for that issue.
Thanks for the heads up though.
Offline