kadamb
kadamb

Reputation: 1738

ps aux | grep between two similar processes

I have written a script, which checks for process, if its running or not. If not then it starts the process. Lets say I have few processes running like this :

root      5780  0.0  2.2 3168184 85828 ?       Sl   09:02   0:15 /usr/bin/java -jar /home/vtermina/private/crons/jar/consumer-1.0.jar promotionalSecond

root      5780  0.0  2.2 3168184 85828 ?       Sl   09:02   0:15 /usr/bin/java -jar /home/vtermina/private/crons/jar/consumer-1.0.jar promotionalSecond backup

root      8989  0.0  1.4 2966364 57540 ?       Sl   09:04   0:07 /usr/bin/java -jar /home/vtermina/private/crons/jar/update-report-1.0.jar Rb1 backup

So I use following command to check if a process is runnig or not :

ps uax|grep -w "consumer-1.0.jar promotionalSecond" |grep -v grep|wc -l

This command returns me one, if it finds a process running. It was working fine till recently, when I started using some backup consumers also. Now if a backup consumer is running,this command returns 1,even if consumer is not running,

How can I grep for exact words in ps aux. So that my command gives correct result.

Upvotes: 1

Views: 1178

Answers (1)

kadamb
kadamb

Reputation: 1738

Doing some research , I got the answer. Using "$" in search-term, does,what is required. $ tells that the search term ends there.

Like, if I want to check only promotionalSecond and not backup, following command works perfectly.

ps uax|grep -w "consumer-1.0.jar promotionalSecond$" |grep -v grep|wc -l

Upvotes: 2

Related Questions