我希望结合以下两个命令:
ps -ef| grep -v grep|grep java | awk ' {print "PID is:" $2}';
PID is:515
PID is:22145
PID is:32703
ps -ef| grep -v grep|grep java
wladmin 515 506 0 Nov03 ? 01:11:39 /web/jdk-18.0.1.1/bin/java -jar remoting.jar -workDir /web/jenkinsprod -jar-cache /web/jenkinsprod/remoting/jarCache
wladmin 22145 22140 0 Nov04 ? 00:54:18 /web/jdk-18.0.1.1/bin/java -Djava.io.tmpdir=/web/jenkins_windows/tmp -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -jar remoting.jar -workDir /web/jenkins_windows -jar-cache /web/jenkins_windows/remoting/jarCache
wladmin 32703 32699 0 Nov03 ? 01:10:34 /web/jdk-18.0.1.1/bin/java -Djava.io.tmpdir=/web/jenkins/tmp -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -jar remoting.jar -workDir /web/jenkins -jar-cache /web/jenkins/remoting/jarCache
我怎样才能结合这两个命令来得到下面的
期望的输出:
PID is:515
Process Dump is: wladmin 515 506 0 Nov03 ? 01:11:39 /web/jdk-18.0.1.1/bin/java -jar remoting.jar -workDir /web/jenkinsprod -jar-cache /web/jenkinsprod/remoting/jarCache
PID is:22145
Process Dump is: wladmin 22145 22140 0 Nov04 ? 00:54:18 /web/jdk-18.0.1.1/bin/java -Djava.io.tmpdir=/web/jenkins_windows/tmp -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -jar remoting.jar -workDir /web/jenkins_windows -jar-cache /web/jenkins_windows/remoting/jarCache
使用
awk
根据哪个版本
ps
,这可能会列出 pids:请注意,使用
grep '[j]ava'
which 避免了第二次调用grep
.