Need to list 3 days old processes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to list 3 days old processes
# 1  
Old 08-02-2010
Need to list 3 days old processes

Code:
ps -xfu <user name>

this command line will list all the process currently running for <user name>.
I need to filter this output. I need all the process which are running for more than 3 days(excluding demon/sys process) . The list should include PID, PPID, STIME, process/command.

I am using HP-UX machine and I am trying to write a KSH script for this.
Any help will be appreciated.
# 2  
Old 08-02-2010
can you try this ?
Code:
ps -eo pid,ppid,command,stime | grep `perl -MPOSIX -le 'print strftime "%b%d",localtime(time-(3*60*60*24))'`

or

Code:
UNIX95=1 ps -eo pid,ppid,command,stime | grep `perl -MPOSIX -le 'print strftime "%b%d",localtime(time-(3*60*60*24))'`


Last edited by ygemici; 08-02-2010 at 05:05 AM..
# 3  
Old 08-02-2010
Thanks @Ygemici. I tried the command line you provided but returned an error -

Code:
ps: command is not a valid field name
Can't locate POSIX.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1
/opt/perl5/lib/5.00502 /opt/perl5/lib/site_perl/5.005/PA-RISC1.1 /opt/perl5/lib/site_perl/5.005 .).
BEGIN failed--compilation aborted.
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
        [-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
        -f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]


Last edited by Scott; 08-02-2010 at 06:17 AM.. Reason: Code tags, please...
# 4  
Old 08-02-2010
Quote:
Originally Posted by Sriranga
Thanks @Ygemici. I tried the command line you provided but returned an error -

Code:
ps: command is not a valid field name
Can't locate POSIX.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1
/opt/perl5/lib/5.00502 /opt/perl5/lib/site_perl/5.005/PA-RISC1.1 /opt/perl5/lib/site_perl/5.005 .).
BEGIN failed--compilation aborted.
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
        [-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
        -f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]

Hmm probably your perl version is not support posix module : `Can't locate POSIX.pm in @INC (@INC contains: /opt/perl5/lib/5.00502/PA-RISC1.1`

it says `Can't locate POSIX` so cant found it

Then you must update the Perl Smilie
https://h20392.www2.hp.com/portal/sw...uctNumber=PERL
# 5  
Old 08-02-2010
Dude.... its a client production server. I don't have access to install perl. is it not possible to do it without the help of Perl ?

Last edited by Sriranga; 08-02-2010 at 08:57 AM..
# 6  
Old 08-02-2010
Quote:
ps: command is not a valid field name
Also, the command syntax suggested for "ps" is not valid on HP-UX .
Maybe respondant meant?:
Code:
UNIX95=1 ps -eo pid,ppid,comm,stime

However the format of the "stime" column is probably not useful for processing in the suggested Perl program because the field format changes from "HH:MM:SS" to "MMM dD" for processes more than 24 hours old.
# 7  
Old 08-02-2010
Quote:
Originally Posted by methyl
Also, the command syntax suggested for "ps" is not valid on HP-UX .
Maybe respondant meant?:
Code:
UNIX95=1 ps -eo pid,ppid,comm,stime

However the format of the "stime" column is probably not useful for processing in the suggested Perl program because the field format changes from "HH:MM:SS" to "MMM dD" for processes more than 24 hours old.
thanks @methly additional information
perl program's output is month and day of the past times..
maybe could be space in between
Code:
"%b %d"

i know like this `comm gives little command` and `command param gives full command however now we can get the output (
and for HH:MM:SS format i add something )

Code:
# ps -eo pid,ppid,command,stime | grep -E "$(perl -MPOSIX -le 'print strftime "%b %d",localtime(time-(3*60*60*24))')|$(perl -MPOSIX -le 'print strftime "%b %d",localtime(time-(2*60*60*24))')|[0-9]*:[0-9]*:[0-9]*"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files older than 10 days.

Hello all, I want to list the files older than 10 days. Currently am using find ./ -mtime +10 -exec ls -ltr {} \; command. But I want to execute the same command in 16 directories at a time and want an output asking to remove those file? Please help me to design the script. regards, Ajay (3 Replies)
Discussion started by: 02Ajay
3 Replies

2. Shell Programming and Scripting

How can i list files above 5 days old?

HI how can i list files above 5 days old i want to keep only last 5 days application logs Regards, Ben (3 Replies)
Discussion started by: bentech4u
3 Replies

3. HP-UX

listing processes older than n days

Hello; trying to find processes older than n days, mostly user shells Tried the following code on 11.31 box: in this case older than 5 days UNIX95= ps -ef -o user,pid,ppid,cpu,etime,stime | grep "-" | awk '{print $2}' | xargs ps -ef|grep -v '?' |\ awk '$5 !~ ""' | awk '($5 ~ "$(date "+%b")")... (6 Replies)
Discussion started by: delphys
6 Replies

4. AIX

etime - get processes running for more than 30 days

In AIX I am trying to get the processes ran by user declan using the following format: ps -aef -o user,pid,etime,args | grep declan Then I get a result similar to (for example): declan 103264 123-12:47:33 /applications/apache/1.3.39.0/bin/httpd -d /var/applications/apache/www1 ... (0 Replies)
Discussion started by: chipahoys
0 Replies

5. Shell Programming and Scripting

List the files which are older than 7 days

Hi Frnds, I have to list the files which are older than 7 days in the given directory. it should consider only the files and should not show subdirectories. Thanks, Raja (3 Replies)
Discussion started by: smr_rashmy
3 Replies

6. Solaris

List of files last modified 30/60/90 days

Hi, I want to find the list of all the files under a directory (including it's subdirectories) last modified 30 days, 60 days, 90 days..also I want to find out the rate at which the disk space is growing. Please help. (3 Replies)
Discussion started by: b.paramanatti
3 Replies

7. Shell Programming and Scripting

Need to kill processes that are older than 3 days

Hi, I need a .ksh script that lists all the process that are currently running and older than 3 days. once the process list is available i need to mail the list and then kill those processes. Quick response is highly appreciated :b: Thanks in Advance!!! Sri (3 Replies)
Discussion started by: Sriranga
3 Replies

8. Programming

how to get list of processes

Hi, How can I get a list of all the running processes, in C? (13 Replies)
Discussion started by: yaron
13 Replies

9. Shell Programming and Scripting

List directory 7 days older

Say folder archive/ contains many folder each created on a day. this folder may contain files. i want to write a script to delete all the folder inside archive/ which are 7 days older. i used the below script for the reason. find archive -mtime +7 -type d -exec rm -r {} \; pls suggest me if... (3 Replies)
Discussion started by: krishnarao
3 Replies

10. UNIX for Dummies Questions & Answers

list last 10 days modified files

All, Is there is anyother single command that will handle ls -lrt | tail -10 Please let me know Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies
Login or Register to Ask a Question