Register
It is currently Thu Oct 02, 2014 8:27 am

Need a little help with pgrep


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed Aug 19, 2009 9:07 am   

Joined: Wed Aug 19, 2009 8:57 am
Posts: 5
I have the following two processes running on my system:

root 18890 18867 0 Jul02 ? 04:14:13 /usr/java/jdk/bin/java -Dprogram.name=run.sh -server -XX:MaxPermSize=256m -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Duser.timezone=CST6CDT -Djava.endorsed.dirs=/usr/local/jboss-4.0.5.GA/lib/endorsed -classpath /usr/local/jboss-4.0.5.GA/bin/run.jar:/usr/java/jdk/lib/tools.jar org.jboss.Main -c bekaert

root 6412 6389 0 Jun30 ? 02:50:35 /usr/java/jdk/bin/java -Dprogram.name=run.sh -server -XX:MaxPermSize=256m -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Duser.timezone=EST5EDT -Djava.endorsed.dirs=/usr/local/jboss-4.0.5.GA/lib/endorsed -classpath /usr/local/jboss-4.0.5.GA/bin/run.jar:/usr/java/jdk/lib/tools.jar org.jboss.Main -c bekaertorrville

I need to know the pid of bekaert but not of bekaertorrville. Originally I have been using pgrep to get the pid of our jboss instances but I ran into a snag with these two instances. `pgrep -f "org.jboss.Main -c bekaert"` returns the pids for both instances and kills my script. How can I have pgrep only return bekaert?


Top
 Profile  
 PostPosted: Wed Aug 19, 2009 9:15 am   

Joined: Wed Aug 19, 2009 8:57 am
Posts: 5
Okay, it seems like adding $ to the end of my expression did the trick.
pgrep -f "org.jboss.Main -c bekaert$"
only returned the instance I was looking for. I tried it for bekaertorrville and returned only that pid respectively.


Top
 Profile  
 PostPosted: Thu Aug 20, 2009 1:13 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
To clarify, this is because you're adding the "end-of-line"-character used in regular expressions. Obviously pgrep supports regexp use :)

^ is "beginning of line"
$ is "end of line"

Best regards
Fredrik Eriksson


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP