LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2009, 09:30 PM   #1
ahpin
Member
 
Registered: Oct 2003
Location: Malaysia
Distribution: Redhat, Mandrake 9.1, SuSE Linux
Posts: 32

Rep: Reputation: 15
how to grep the process running more than 30 days only?


is there a way for me to grep the process that running more than 30 days only using linux command or script?

example:
i do ps -ef to list out the process, then i want to filter only the process that always running more than 30 days..
 
Old 08-18-2009, 10:18 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
first, look thru all the output formatting options for "ps". I started with "ps -e -o start". Once you have the right format, you can sort, grep, etc.

grep by itself just looks for keywords (or regexes).
 
Old 08-23-2009, 09:16 PM   #3
ahpin
Member
 
Registered: Oct 2003
Location: Malaysia
Distribution: Redhat, Mandrake 9.1, SuSE Linux
Posts: 32

Original Poster
Rep: Reputation: 15
ps aux | grep -w <process name>| grep -v grep | ps -o pid,etime,cmd `awk '{ print $2 }'`

i'm using above command to grab the process and manage to get something like below.

11722 31-16:32:15 <command line>
11723 31-16:32:15 <command line>
11739 31-16:32:15 <command line>
6829 28-10:43:13 <command line>
6830 28-10:43:13 <command line>
6845 28-10:43:12 <command line>


Anyway,is there a way for me to just grab the day more than 30 in this case?

Also, i tried to put this into the script variable, but there is error...
example as below is nto working:
pid=ps aux | grep -w <process name>| grep -v grep | ps -o pid,etime,cmd `awk '{ print $2 }'`


any advice is appreciated...
 
Old 08-23-2009, 10:13 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Please give us the error that's being produced -- that'd help diagnose where the problem is occurring.

Plus, I'm speculating that you may be able/needing to involve the `date` command but this is pure speculation. Just show us the error you get, first.

Sasha

EDIT: looks like you're missing a pipe or a comma, before the awk command.
 
Old 08-23-2009, 11:01 PM   #5
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
<grinds teeth and bangs forehead against keyboard for about five seconds>

Um, guys (of either gender), since it's Linux, how about this?
Code:
find /proc -maxdepth 1 -name '[0-9]*' -mtime +30 | sed 's/^......//'
 
Old 08-23-2009, 11:27 PM   #6
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Quote:
Originally Posted by wje_lq View Post
<grinds teeth and bangs forehead against keyboard for about five seconds>

Um, guys (of either gender), since it's Linux, how about this?
Code:
find /proc -maxdepth 1 -name '[0-9]*' -mtime +30 | sed 's/^......//'
Sure if it works for the OP, great! There's usually more than one way to 'skin a cat running Linux'.

Sasha
 
Old 08-24-2009, 12:53 AM   #7
ahpin
Member
 
Registered: Oct 2003
Location: Malaysia
Distribution: Redhat, Mandrake 9.1, SuSE Linux
Posts: 32

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by GrapefruiTgirl View Post
Please give us the error that's being produced -- that'd help diagnose where the problem is occurring.

Plus, I'm speculating that you may be able/needing to involve the `date` command but this is pure speculation. Just show us the error you get, first.

Sasha

EDIT: looks like you're missing a pipe or a comma, before the awk command.


if i just execute the command from the shell, it is working...but when i put into the the script, it is showing the error...i think it might be related to the quote use but i just can't figured out which one

pg009> ./getoldprocess.sh
./getoldprocess.sh: line 5: { print $2 }: command not found
pg009>

i=`ps aux | grep -w run | grep -v grep | ps -o pid,etime `awk '{ print $2 }'` `
 
Old 08-24-2009, 01:10 AM   #8
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Code:
i=$(ps aux | grep -w run | grep -v grep | ps -o pid,etime `awk '{ print $2 }'` )
Try the above, for the heck of it. But I still think you're missing a pipe.

Sasha
 
Old 08-24-2009, 05:48 AM   #9
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by GrapefruiTgirl View Post
There's usually more than one way to 'skin a cat running Linux'.
Especially on Caturday.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dd copy running for 4 days, can i check status somehow? rwreed Linux - Newbie 10 02-25-2009 09:27 PM
Get Process size and Thread count for a particular running process haseit Linux - Newbie 2 01-22-2009 11:09 PM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 03:47 AM
Cron backup script stops running after a few days brokenpromises Linux - Server 5 04-05-2008 05:30 AM
Azureus freezing up, was running fine a couple of days ago. ChootarLaal Ubuntu 1 03-13-2008 09:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration