Linuxサーバーのプロセスを確認するスクリプトがあります。
ebond-dbreader-bbg
たとえば、Server 1というコンポーネントとebond-dbreader-bbg-cbrt
Server 1という別のコンポーネントがあります。
次のコマンドを実行すると、カウント1にする必要がありますが、カウント2を返しますが、bond-dbreader-bbg
name内で混乱しますebond-dbreader-bbg-cbrt
。
スクリプト減算変数:
ps -ef | grep ebond-dbreader-bbg | grep -v grep| grep -Ev " pts/[0-9]{1,4}" |wc -l
私が得る出力は2です。
なぜなら
ps -ef | grep ebond-dbreader-bbg
2つのプロセスがありますが、1つは名前が異なります。下記をご覧ください。
[ebondgen@ebondfm1i20 bin]$ ps -ef | grep ebond-dbreader-bbg | grep -v grep| grep -Ev " pts/[0-9]{1,4}" |wc -l
2
[ebondgen@ebondfm1i20 bin]$ ps -ef | grep ebond-dbreader-bbg
ebond 127056 1 2 00:15 ? 00:25:14 /opt/java1.8/bin/java -Xms2048M -Xmx2048M -Dprogram.name=ebond-dbreader-bbg-cbrt -Dlog4j.configuration=file:resource/log4j.xml -Dproperty.file=resource/dbr.properties -DzooKeeperHosts=ebond-zookeeper1-uat.zit.commerzbank.com:2181 -DapplicationId=ebond-dbreader-bbg-cbrt-0 -server -XX:+UseConcMarkSweepGC -XX:+AlwaysPreTouch -XX:+PrintTenuringDistribution -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintAdaptiveSizePolicy -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+UseGCLogFileRotation -XX:GCLogFileSize=1000K -XX:NumberOfGCLogFiles=5 -Xloggc:/var/eBondTS/log/ebond-dbreader-bbg-cbrt.gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/eBondTS/log/ebond-dbreader-bbg-cbrt.hprof -cp :/opt/eBondTS/ebond-dbreader-bbg-cbrt/20191114135302_01000040/resource:/opt/eBondTS/ebond-dbreader-bbg-cbrt/20191114135302_01000040/lib/* -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=13075 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=true -Dcom.sun.management.jmxremote.access.file=/opt/eBondTS/ebond-certificates/current/resource/jmxWrite.access -Djava.security.auth.login.config=/opt/eBondTS/ebond-certificates/current/resource/ldap.conf -Dcom.sun.management.jmxremote.login.config=LdapSSLNoVerify -Djavax.net.ssl.keyStore=/opt/eBondTS/serverkey/keystore -Djavax.net.ssl.keyStorePassword=T55EJqVOdPLyVdnYpLMV -Djavax.net.ssl.trustStore=/opt/eBondTS/ebond-certificates/current/resource/truststore -Djavax.net.ssl.trustStorePassword=T55EJqVOdPLyVdnYpLMV -Dcom.sun.management.jmxremote.debug=true -Dbuild.number=1.0.40-01000040 -Dsun.net.inetaddr.ttl=0 com.drkw.dbreader.DbReader
ebond 127572 1 2 00:15 ? 00:25:39 /opt/java1.8/bin/java -Xms2048M -Xmx2048M -Dprogram.name=ebond-dbreader-bbg -Dlog4j.configuration=file:resource/log4j.xml -Dproperty.file=resource/dbr.properties -DzooKeeperHosts=ebond-zookeeper1-uat.zit.commerzbank.com:2181 -DapplicationId=ebond-dbreader-bbg-0 -server -XX:+UseConcMarkSweepGC -XX:+AlwaysPreTouch -XX:+PrintTenuringDistribution -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintAdaptiveSizePolicy -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+UseGCLogFileRotation -XX:GCLogFileSize=1000K -XX:NumberOfGCLogFiles=5 -Xloggc:/var/eBondTS/log/ebond-dbreader-bbg.gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/eBondTS/log/ebond-dbreader-bbg.hprof -cp :/opt/eBondTS/ebond-dbreader-bbg/20191114135312_01000040/resource:/opt/eBondTS/ebond-dbreader-bbg/20191114135312_01000040/lib/* -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=13074 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=true -Dcom.sun.management.jmxremote.access.file=/opt/eBondTS/ebond-certificates/current/resource/jmxWrite.access -Djava.security.auth.login.config=/opt/eBondTS/ebond-certificates/current/resource/ldap.conf -Dcom.sun.management.jmxremote.login.config=LdapSSLNoVerify -Djavax.net.ssl.keyStore=/opt/eBondTS/serverkey/keystore -Djavax.net.ssl.keyStorePassword=T55EJqVOdPLyVdnYpLMV -Djavax.net.ssl.trustStore=/opt/eBondTS/ebond-certificates/current/resource/truststore -Djavax.net.ssl.trustStorePassword=T55EJqVOdPLyVdnYpLMV -Dcom.sun.management.jmxremote.debug=true -Dbuild.number=1.0.40-01000040 -Dsun.net.inetaddr.ttl=0 com.drkw.dbreader.DbReader
ebondgen 134027 91663 0 19:12 pts/5 00:00:00 grep ebond-dbreader-bbg
このコマンドが必要です。
ps -ef | grep ebond-dbreader-bbg | grep -v grep| grep -Ev " pts/[0-9]{1,4}" |wc -l
2は正しくないため、2の代わりに1のみを返します。この問題を解決する方法を知っている人はいますか?
変数付きスクリプト
#!/bin/bash
outputDir=/tmp
touch $outputDir/checkOutput.txt
currentServerRole=$(/opt/eBondTS/ebond-server-scripts/current/bin/getServerRole.sh)
excludedComponents=('ebond-devops-scripts' 'ebond-checksum-validator' 'ebond-platform-webtool' 'ebond-deployment-guineapigone' 'ebond-deployment-guineapigtwo' 'ebond-deployment-guineapigthree' 'ebond-declarative-release' 'ebond-rhl-installer' 'ebond-web-broker' 'ebond-curvesubscriber' 'ebond-ampsperformancepublisher' 'ebond-ampsperformancesubscriber' 'ebond-diva-latencycheck' 'ebond-gal-latencycheck' 'ebond-neonpricerec-all' 'ebond-neonpricerec-banks' 'ebond-neonpricerec-chf' 'ebond-neonpricerec-covered' 'ebond-neonpricerec-credit' 'ebond-neonpricerec-derivatives' 'ebond-neonpricerec-emlm1' 'ebond-neonpricerec-emlm2' 'ebond-neonpricerec-other' 'ebond-neonpricerec-rates' 'ebond-neonpricerec-strips' 'ebond-neonpricerec-ust' 'razor-diva-test' 'ebond-reconcile-tool-tp-icap' 'ebond-reconcile-tool-bgc' 'ebond-reconcile-tool-tradition' 'ebond-zookeeper' 'ebond-ebond2bbg-reconciler' 'ebond-overnight-rates-subscriber' 'ebond-curvesubscriber' 'ebond-instrumentstatic-subscriber' 'ebond-userstatic-subscriber' 'ebond-web-broker')
ebond_components=$(grep runInServerRoles /opt/eBondTS/ebond*/current/etc/deployment.properties| awk -F'/' '{print $4}')
razor_components=$(grep -s runInServerRoles /opt/eBondTS/razor*/current/etc/deployment.properties| awk -F'/' '{print $4}')
all_components=$(echo ${ebond_components} ${razor_components})
echo "Id,ComponentName,CellName,ConfiguredYmlValue,BoxRunLevel,ExpectedToRun,CurrentProcessCount,CheckStatus" >> $outputDir/finalOutput.txt
for componentName in $all_components
do
expectedToRunIn=$(grep -s runInServerRoles /opt/eBondTS/$componentName/current/etc/deployment.properties | sed 's,runInServerRoles=,,')
configuration=$(grep -s configuration /opt/eBondTS/$componentName/current/etc/deployment.properties| sed 's,configuration=,,')
pkgType=$(grep -s packageType /opt/eBondTS/$componentName/current/etc/deployment.properties | sed 's,packageType=,,')
cellName=$(grep -s cellTeamName /opt/eBondTS/$componentName/current/etc/deployment.properties| sed 's,cellTeamName=,,')
checkStatus="NOT-OK-CantCheck!!!!"
expectedCount="No"
if [ "$currentServerRole" == "$expectedToRunIn" ]; then
expectedCount="Yes"
fi
if [ "$expectedToRunIn" == "all" ]; then
expectedCount="Yes"
fi
if [[ pkgType = java ]]; then
processes=$(ps -ef | grep "=$componentName " | grep -v grep| grep -Ev " pts/[0-9]{1,4}" |wc -l)
else
processes=$(ps -ef | grep $componentName | grep -v grep| grep -Ev " pts/[0-9]{1,4}" |wc -l)
fi
答え1
IIUC、あなたが望むもの:
ps -ef | grep '[e]bond-dbreader-bbg ' | wc -l
このソリューションは必要ありませんgrep -v grep
。