Using perl/shell scripts to kill processes more than x days old

J

Jimmy

Hi Folks,

OS : Solaris 8

I have a question regarding killing processes on a unix server. I
would like to run a cron job to kill processes run by certain binaries
that are more than 2 weeks old. I had a look at using the awk combined
with the output of ps but this doesn'tgive me what I want as the
output of ps is limited in what
it outputs as a start date of the process. Has anyone used perl or
shell scripting to come up with a nice way of doing this.

Regards,

Jimmy
 
S

Stefan

Jimmy said:
Hi Folks,

OS : Solaris 8

I have a question regarding killing processes on a unix server. I
would like to run a cron job to kill processes run by certain binaries
that are more than 2 weeks old. I had a look at using the awk combined
with the output of ps but this doesn'tgive me what I want as the
output of ps is limited in what
it outputs as a start date of the process. Has anyone used perl or
shell scripting to come up with a nice way of doing this.

Regards,

Jimmy


The ps-command still is the best way to get the information you want. You
can select alternative fields using the -o switch. If you execute and parse
the following command;

ps -A -o pid,user,etime,comm

you only need to convert/check the delta elapsed-time [[d-]hh:]mm:ss (etime)
and limit on user and/or binaries (comm). I suspect the ps/awk or ps/ksh or
ps/perl part won't be a problem.

Good luck,
Stefan
 
W

Walt Fles

Your best bet is to go into /proc and disect the data yourself, instead of
relying on what formatting commands ( ie, ps ) gives you.
 
M

Martien Verbruggen

On Sat, 28 Jun 2003 16:30:13 GMT,

[fixed Jeopardy style post]

If you use ps, it's probably best to use the -o option (look at etime,
so your output is a bit more predictable, and probably easier to use.
Your best bet is to go into /proc and disect the data yourself, instead of
relying on what formatting commands ( ie, ps ) gives you.

Perl specific:

If you want to use the /proc filesystem on Solaris, you're probably
best off using the Proc::processTable module, which does all of the
handling of the structs stored there for you.

Martien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top