をクリーンアップこれは私が2列と、各プロセスのコマンドラインで-f
オプション次のパスの最後の成分を抽出しようとしているPS -ef出力
$ ps -ef | grep logstash
hdfs 72561 1 58 10:08 pts/5 00:59:35 /usr/java/default/bin/java -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Xmx1g -Xss2048k -Djffi.boot.library.path=/grid01/es/CF_STAGE_ES/logstash-2.2.2/vendor/jruby/lib/jni -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/grid01/es/CF_STAGE_ES/logstash-2.2.2/heapdump.hprof -Xbootclasspath/a:/grid01/es/CF_STAGE_ES/logstash-2.2.2/vendor/jruby/lib/jruby.jar -classpath : -Djruby.home=/grid01/es/CF_STAGE_ES/logstash-2.2.2/vendor/jruby -Djruby.lib=/grid01/es/CF_STAGE_ES/logstash-2.2.2/vendor/jruby/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main --1.9 /grid01/es/CF_STAGE_ES/logstash-2.2.2/lib/bootstrap/environment.rb logstash/runner.rb agent -f /grid01/es/CF_STAGE_ES/CF_STAGE.es.config
hdfs 96424 1 38 10:27 pts/5 00:31:41 /usr/java/default/bin/java -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Xmx1g -Xss2048k -Djffi.boot.library.path=/grid01/es/CSL_STAGE/logstash-2.2.2/vendor/jruby/lib/jni -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/grid01/es/CSL_STAGE/logstash-2.2.2/heapdump.hprof -Xbootclasspath/a:/grid01/es/CSL_STAGE/logstash-2.2.2/vendor/jruby/lib/jruby.jar -classpath : -Djruby.home=/grid01/es/CSL_STAGE/logstash-2.2.2/vendor/jruby -Djruby.lib=/grid01/es/CSL_STAGE/logstash-2.2.2/vendor/jruby/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main --1.9 /grid01/es/CSL_STAGE/logstash-2.2.2/lib/bootstrap/environment.rb logstash/runner.rb agent -f /grid01/es/CSL_STAGE/CSL_STAGE.es.config
hdfs 136554 1 10 10:57 pts/5 00:05:36 /usr/java/default/bin/java -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Xmx1g -Xss2048k -Djffi.boot.library.path=/grid01/es/SENSE_STAGE/logstash-2.2.2/vendor/jruby/lib/jni -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/grid01/es/SENSE_STAGE/logstash-2.2.2/heapdump.hprof -Xbootclasspath/a:/grid01/es/SENSE_STAGE/logstash-2.2.2/vendor/jruby/lib/jruby.jar -classpath : -Djruby.home=/grid01/es/SENSE_STAGE/logstash-2.2.2/vendor/jruby -Djruby.lib=/grid01/es/SENSE_STAGE/logstash-2.2.2/vendor/jruby/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main --1.9 /grid01/es/SENSE_STAGE/logstash-2.2.2/lib/bootstrap/environment.rb logstash/runner.rb agent -f /grid01/es/SENSE_STAGE/SENSE_STAGE.es.config
hdfs 203513 1 82 11:37 pts/5 00:10:08 /usr/java/default/bin/java -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Xmx1g -Xss2048k -Djffi.boot.library.path=/grid01/es/SMARTSCAN_STAGE/logstash-2.2.2/vendor/jruby/lib/jni -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/grid01/es/SMARTSCAN_STAGE/logstash-2.2.2/heapdump.hprof -Xbootclasspath/a:/grid01/es/SMARTSCAN_STAGE/logstash-2.2.2/vendor/jruby/lib/jruby.jar -classpath : -Djruby.home=/grid01/es/SMARTSCAN_STAGE/logstash-2.2.2/vendor/jruby -Djruby.lib=/grid01/es/SMARTSCAN_STAGE/logstash-2.2.2/vendor/jruby/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main --1.9 /grid01/es/SMARTSCAN_STAGE/logstash-2.2.2/lib/bootstrap/environment.rb logstash/runner.rb agent -f /grid01/es/SMARTSCAN_STAGE/SMARTSCAN_STAGE.es.config
hdfs 602508 1 10 Aug25 ? 6-18:21:48 /usr/java/default/bin/java -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Xmx1g -Xss2048k -Djffi.boot.library.path=/grid01/es/logstash-2.2.2/vendor/jruby/lib/jni -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/grid01/es/logstash-2.2.2/heapdump.hprof -Xbootclasspath/a:/grid01/es/logstash-2.2.2/vendor/jruby/lib/jruby.jar -classpath : -Djruby.home=/grid01/es/logstash-2.2.2/vendor/jruby -Djruby.lib=/grid01/es/logstash-2.2.2/vendor/jruby/lib -Djruby.script=jruby -Djruby.shell=/bin/sh org.jruby.Main --1.9 /grid01/es/logstash-2.2.2/lib/bootstrap/environment.rb logstash/runner.rb agent -f /grid01/es/logstash-2.2.2/AERO_STAGE_es.config
-ef私のPSの出力です。
私はそれをクリーンアップするために以下のコードを使用しています。このようになります
ps -ef | grep logstash | grep -v grep| awk -F" " '{print "Logstash is running for " substr($NF,7,10) " & PID number is " $2 }'
:
Logstash is running for S/CF_STAGE.es.config & PID number is 72561
Logstash is running for CSL_STAGE.es.config & PID number is 96424
Logstash is running for E/SENSE_STAGE.es.config & PID is
Logstash is running for STAGE/SMARTSCAN_STAGE.es.co & PID number is 203513
Logstash is running for .2.2/AERO_STAGE_es.config & PID number is 602508
今の問題は、私はちょうどそれだけで(次のようになりたいですトピック名& PID):
Logstash is running for CF_STAGE & PID number is 72561
Logstash is running for CSL_STAGE & PID number is 96424
Logstash is running for SENSE_STAGE & PID number 136554
Logstash is running for SMARTSCAN_STAGE & PID number is 203513
Logstash is running for AERO_STAGE & PID number is 602508
[宿題](http://stackoverflow.com/q/40309305/3776858)? – Cyrus
明らかに、 'substr($ NF、7,10)'を最初からオフセットをハードコーディングするのではなく、フィールドの終わりから固定長のものを取り除くものに置き換えたいとします。 – tripleee
も参照してください。[grep'の無駄な使い方](http://www.iki.fi/era/unix/award.html#grep) – tripleee