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
두 개의 프로세스가 있지만 하나는 이름이 다릅니다. 아래를 참조하세요.
[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
.