Kill PID with one liner

Hello Friends,

I've been trying to write a one line which checks java processes and filter them for a user (testuser) and then check process arguments with PARGS command and then check if there is certain patterns exists in pargs output then kill the process.

I have tried the following so far, could you please help to complete the one liner? I also appreciate if you could verify what I'm doing is the right way to achive it or not.

ps -ef | grep java | grep -v grep | nawk '$1~/testuser/{system( "pargs "$2"|grep -i tomcat.*/conf/.*properties" )}'

output is:

argv[1]: -Djava.util.logging.config.file=/opt/test/customeradaptations/tomcat-mgway/conf/logging.properties
argv[5]: -Ddatabase.properties=/opt/test/customeradaptations/tomcat-mgway/conf/database.properties
argv[17]: -DmsisdnRangeFile=/opt/test/customeradaptations/tomcat-mgway/conf/msisdnRangeFile.properties

So I would like to kill the process as there are matching patterns in the output lines.

Thanks in advance,
Kind Regards
EAGL�

Why do you need pargs when ps -f does a full listing of process arguments? Try

ps -ef | nawk '/java/ && $1 ~ /testuser/ && /tomcat.*\/conf\/.*properties/ {print $2}'

Once you're happy with the result, you can kill $(...above...) .

Hello Rudic,

but this part

/tomcat.*\/conf\/.*properties/

comes with the pargs command output not directly with "ps -ef" output. so I need to apply pargs command to see arguments and if the arguments contains

/tomcat.*\/conf\/.*properties/

afterwards i can be sure that tomcat process ID is correct so can be killed..

I have checked again;

the following gives arguments of desired PID. I keep the PID in sprintf so that i will use it again as i have to call it again (in Kill -15). I could not complete after the following one, any help appreciated.

pargs $(ps -ef | nawk '/java/ && !/grep/ && $1~/ericsson/{PID = sprintf("%d",$2);print PID}')