PS -EF | GREP JAVA Modification


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PS -EF | GREP JAVA Modification
# 1  
Old 03-04-2015
RedHat PS -EF | GREP JAVA Modification

Hi,

When I do ps -ef | grep java I get the following output on my server, But how to get just the last line and the pid....something like:-
Code:
wasadmin@ccos2104:TEST:bin> ps -ef | grep java
wasadmin  5935 54288  0 12:39 pts/8    00:00:00 grep java
 ccos2104Cell ccos2104 aa

==============================================

wasadmin@ccos2104:TEST:bin> ps -ef | grep java
wasadmin  5935 54288  0 12:39 pts/8    00:00:00 grep java
wasadmin 14813     1  1 Jan14 ?        18:16:42 /u01/was85/java/bin/java -Declipse.security -Dwas.status.socket=35920 -Dosgi.install.area=/u01/was85 -Dosgi.configuration.area=/u01/was85/profiles/appsrv/servers/aa/configuration -Djava.awt.headless=true -Dosgi.framework.extensions=com.ibm.cds,com.ibm.ws.eclipse.adaptors -Xshareclasses:name=webspherev85_1.6_64_%g,nonFatal -Dcom.ibm.xtq.processor.overrideSecureProcessing=true -Xbootclasspath/p:/u01/was85/java/jre/lib/ibmorb.jar -classpath /u01/was85/profiles/appsrv/properties:/u01/was85/properties:/u01/was85/lib/startup.jar:/u01/was85/lib/bootstrap.jar:/u01/was85/lib/jsf-nls.jar:/u01/was85/lib/lmproxy.jar:/u01/was85/lib/urlprotocols.jar:/u01/was85/deploytool/itp/batchboot.jar:/u01/was85/deploytool/itp/batch2.jar:/u01/was85/java/lib/tools.jar -Dibm.websphere.internalClassAccessMode=allow -verbose:gc -Xms2560m -Xmx2560m -Xcompressedrefs -Xscmaxaot4M -Xscmx90M -Dws.ext.dirs=/u01/was85/java/lib:/u01/was85/profiles/appsrv/classes:/u01/was85/classes:/u01/was85/lib:/u01/was85/installedChannels:/u01/was85/lib/ext:/u01/was85/web/help:/u01/was85/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime -Dderby.system.home=/u01/was85/derby -Dcom.ibm.itp.location=/u01/was85/bin -Djava.util.logging.configureByServer=true -Duser.install.root=/u01/was85/profiles/appsrv -Djava.ext.dirs=/u01/was85/tivoli/tam:/u01/was85/java/jre/lib/ext -Djavax.management.builder.initial=com.ibm.ws.management.PlatformMBeanServerBuilder -Dpython.cachedir=/u01/was85/profiles/appsrv/temp/cachedir -Dwas.install.root=/u01/was85 -Djava.util.logging.manager=com.ibm.ws.bootstrap.WsLogManager -Dserver.root=/u01/was85/profiles/appsrv -Dcom.ibm.security.jgss.debug=off -Dcom.ibm.security.krb5.Krb5Debug=off -Dprobe.id=ccos2104_nwideweb_net-aa -Dprobe.log.dir=/u01/was85/profiles/appsrv/logs/aa -Dserver.log.root=/u01/was85/profiles/appsrv/logs/aa -Djava.library.path=/u01/was85/lib/native/linux/x86_64/:/u01/was85/java/jre/lib/amd64/compressedrefs:/u01/was85/java/jre/lib/amd64:/u01/was85/bin:/u01/was85/nulldllsdir:/usr/lib: -Djava.endorsed.dirs=/u01/was85/endorsed_apis:/u01/was85/java/jre/lib/endorsed -Djava.security.auth.login.config=/u01/was85/profiles/appsrv/properties/wsjaas.conf -Djava.security.policy=/u01/was85/profiles/appsrv/properties/server.policy com.ibm.wsspi.bootstrap.WSPreLauncher -nosplash -application com.ibm.ws.bootstrap.WSLauncher com.ibm.ws.runtime.WsServer /u01/was85/profiles/appsrv/config ccos2104Cell ccos2104 aa

Moderator's Comments:
Mod Comment
Please wrap all code, files, input and output/errors in CODE tags.
It makes it easier to read and preserves multiple spaces and doesn't wrap lines.

Last edited by rbatte1; 03-05-2015 at 12:15 PM..
# 2  
Old 03-05-2015
Quote:
Originally Posted by crosairs
Hi,

When I do ps -ef | grep java I get the following output on my server, But how to get jsut the last line and the pid....something like
Code:
wasadmin@ccos2104:TEST:bin> ps -ef | grep java
wasadmin 5935 54288 0 12:39 pts/8 00:00:00 grep java
ccos2104Cell ccos2104 aa
 
==============================================
 
wasadmin@ccos2104:TEST:bin> ps -ef | grep java
wasadmin 5935 54288 0 12:39 pts/8 00:00:00 grep java
wasadmin 14813 1 1 Jan14 ? 18:16:42 /u01/was85/java/bin/java -Declipse.security -Dwas.status.socket=35920 -Dosgi.install.area=/u01/was85 -Dosgi.configuration.area=/u01/was85/profiles/appsrv/servers/aa/configuration -Djava.awt.headless=true -Dosgi.framework.extensions=com.ibm.cds,com.ibm.ws.eclipse.adaptors -Xshareclasses:name=webspherev85_1.6_64_%g,nonFatal -Dcom.ibm.xtq.processor.overrideSecureProcessing=true -Xbootclasspath/p:/u01/was85/java/jre/lib/ibmorb.jar -classpath /u01/was85/profiles/appsrv/properties:/u01/was85/properties:/u01/was85/lib/startup.jar:/u01/was85/lib/bootstrap.jar:/u01/was85/lib/jsf-nls.jar:/u01/was85/lib/lmproxy.jar:/u01/was85/lib/urlprotocols.jar:/u01/was85/deploytool/itp/batchboot.jar:/u01/was85/deploytool/itp/batch2.jar:/u01/was85/java/lib/tools.jar -Dibm.websphere.internalClassAccessMode=allow -verbose:gc -Xms2560m -Xmx2560m -Xcompressedrefs -Xscmaxaot4M -Xscmx90M -Dws.ext.dirs=/u01/was85/java/lib:/u01/was85/profiles/appsrv/classes:/u01/was85/classes:/u01/was85/lib:/u01/was85/installedChannels:/u01/was85/lib/ext:/u01/was85/web/help:/u01/was85/deploytool/itp/plugins/com.ibm.etools.ejbdeploy/runtime -Dderby.system.home=/u01/was85/derby -Dcom.ibm.itp.location=/u01/was85/bin -Djava.util.logging.configureByServer=true -Duser.install.root=/u01/was85/profiles/appsrv -Djava.ext.dirs=/u01/was85/tivoli/tam:/u01/was85/java/jre/lib/ext -Djavax.management.builder.initial=com.ibm.ws.management.PlatformMBeanServerBuilder -Dpython.cachedir=/u01/was85/profiles/appsrv/temp/cachedir -Dwas.install.root=/u01/was85 -Djava.util.logging.manager=com.ibm.ws.bootstrap.WsLogManager -Dserver.root=/u01/was85/profiles/appsrv -Dcom.ibm.security.jgss.debug=off -Dcom.ibm.security.krb5.Krb5Debug=off -Dprobe.id=ccos2104_nwideweb_net-aa -Dprobe.log.dir=/u01/was85/profiles/appsrv/logs/aa -Dserver.log.root=/u01/was85/profiles/appsrv/logs/aa -Djava.library.path=/u01/was85/lib/native/linux/x86_64/:/u01/was85/java/jre/lib/amd64/compressedrefs:/u01/was85/java/jre/lib/amd64:/u01/was85/bin:/u01/was85/nulldllsdir:/usr/lib: -Djava.endorsed.dirs=/u01/was85/endorsed_apis:/u01/was85/java/jre/lib/endorsed -Djava.security.auth.login.config=/u01/was85/profiles/appsrv/properties/wsjaas.conf -Djava.security.policy=/u01/was85/profiles/appsrv/properties/server.policy com.ibm.wsspi.bootstrap.WSPreLauncher -nosplash -application com.ibm.ws.bootstrap.WSLauncher com.ibm.ws.runtime.WsServer /u01/was85/profiles/appsrv/config ccos2104Cell ccos2104 aa

Hello crosairs,
Quote:
When I do ps -ef | grep java I get the following output on my server, But how to get jsut the last line and the pid....something like

wasadmin@ccos2104:TEST:bin> ps -ef | grep java
wasadmin 5935 54288 0 12:39 pts/8 00:00:00 grep java
ccos2104Cell ccos2104 aa
The first line wasadmin 5935 54288 0 12:39 pts/8 00:00:00 grep java
is NOT a actual process it is a process of the command itself, so if you do the following command it shoult not come then.
Code:
ps -ef | grep -v "grep" | grep java

Now if we want to get output for ccos2104Cell ccos2104 aa then following may help.
Code:
ps -ef | grep -v "grep" | grep "java" | awk '{print $(NF-2) OFS $(NF-1) OFS $NF}'

On a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk. Hope this helps.


Thanks,
R. Singh

Last edited by rbatte1; 03-05-2015 at 12:16 PM.. Reason: Added suggestion for awk oin SunOS and solaris system
# 3  
Old 03-05-2015
I'm confused a little. perhaps some good practice will help you whilst I try to work out what you need.

If you change your command to be ps -ef | grep jav[a] then you will only get the header and any real java processes, i.e. your grep will be excluded. If you want just a few columns from that very wide output, consider the -o formatting flag for the command instead, perhaps something like this will meet your needs if you are sure that these is just one real java process:-
Code:
ps -e -o pid= -o comm= | grep jav[a] | read PID COMM


I hope that this helps,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ps -ef | grep java | wc -l

Hi all i have a syntax , Can some one please give me a script 1, I need to check and execute the command. ps -ef | grep java | wc -l 5 Output should me 5 if not have to run the command: ps -ef | grep java the following java process... (11 Replies)
Discussion started by: suresh_krish
11 Replies
Login or Register to Ask a Question