Operating System - HP-UX
1834817 Members
2595 Online
110070 Solutions
New Discussion

Can I use ps to identify processes more than 30 days old?

 
Preet Dhillon
Advisor

Can I use ps to identify processes more than 30 days old?

I'd like to kill all processes owned by the 'lp' user which are more than 30 days old. I can get a list of these processes using 'ps -f -u lp' but I don't know how to compare the date in the output with the current date to identify which are more than 30 days old. Can anyone help ? Many thanks in advance.
Nothing succeeds like excess
5 REPLIES 5
Thierry Poels_1
Honored Contributor

Re: Can I use ps to identify processes more than 30 days old?

hi,
'ps' displays the starting date of a process if its older than 24 hours. So at the end of the month you could select the processes of the previous month and kill them.

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Andreas Voss
Honored Contributor

Re: Can I use ps to identify processes more than 30 days old?

Hi,

here a quick and dirty script to do this.
(i used the touch command to have a file for every process with the same time as the pid and use find to get the older ones).

#!/bin/sh

LANG=C # set default language

mkdir -p /var/tmp/pstmp 2>&- # create temp dir
rm -f /var/tmp/pstmp/* # purge temp dir

cd /var/tmp/pstmp || exit 1

# i've added grep -v lpsched to prevent stopping the scheduler at all
ps -fulp|grep -v lpsched|awk '{
month=0;
if($5 == "Jan") month=1;
if($5 == "Feb") month=2;
if($5 == "Mar") month=3;
if($5 == "Apr") month=4;
if($5 == "May") month=5;
if($5 == "Jun") month=6;
if($5 == "Jul") month=7;
if($5 == "Aug") month=8;
if($5 == "Sep") month=9;
if($5 == "Oct") month=10;
if($5 == "Nov") month=11;
if($5 == "Dec") month=12;
if(month > 0)
printf("%s %02d%02d0000\n",$2,month,$6);
}' |while read pid stamp
do
touch -t $stamp $pid # touch a reference file for every pid
done
find [0-9]* -mtime +30 2>&-|while read pid # find files older than 30 days
do
kill $pid # kill it
done
cd /
rm -rf /var/tmp/pstmp # cleanup

Regards
John Palmer
Honored Contributor

Re: Can I use ps to identify processes more than 30 days old?

How about a monthly reboot?
Bill McNAMARA_1
Honored Contributor

Re: Can I use ps to identify processes more than 30 days old?

you might want to look at the output of
lpstat -t and cancel using the cancel command the job number.. that's assuming the lp user is doing lp print commands.

Later,
bill
It works for me (tm)
Vincenzo Restuccia
Honored Contributor

Re: Can I use ps to identify processes more than 30 days old?

ps -ef|grep -i "Mar 1"|grep -i lp