#!/bin/bash
# Days and Procs declaration
DAYS="3"
PROCS="dyyno"

# 3 days Old date
AGO=$(date --date="$DAYS days ago" +"%b %d")

# Getting pids
PIDS=$(ps eaxo bsdstart,cmd,pid | egrep "^$AGO"' | egrep "$PROCS" | awk '{ print $4}')

# killing the processes
echo "Killing $PROCS process created $AGO days ago"
kill -9 $PIDS

here i wanted to take the log file associated with the running process (dyyno process) and pass a parameter "0"


Can anyone help me pls@@


Thnxxx in advance

Recommended Answers

All 3 Replies

Hey there,

I'm sure what you're shooting for but, maybe:

LOG=${PROCS}.log

$LOG "0"

or

echo "0" >>$LOG

Other than that, I'll need more specifics.

Best wishes,

Mike

Thnxxx Mike... This is my question
I want to write a shell script that kills all processes that satisfy the following conditions:

a. The process is > 3 days old.
b. A log file associated with the process reports a particular parameter as "0"
c. The process name is "dyyno"


this is what i wanted to do... here i am unable to find the log file associated with the particular process!!! Can you help me

Hey, ok, I see where you're coming from now :)

Actually, if you don't know where a particular process logs to, figuring that out from the process itself can be done, but it's not necessarily simple (although, hey, sometimes it is).

I would suggest that you do the log search prior to killing the PIDS associated with the process. Probably the best tools to use (although they may be a bit bulky) would be "lsof" or "truss" ("strace, xtrace, etc, all the same pretty much - depends on your distro of Linux or Unix).

In lsof you could do a simple

lsof|grep PID

and then sift through that output to find any open files associated with the process (eyeball it first and then script the grep out)

for truss, strace, xtrace, etc try doing (I'll use truss for an example, but check the man page for whatever statement-tracing or execution tracing software your distro comes with:

truss -f -p PID|egrep -i 'open|read|write|close'

and check out what files it opens and writes to and then script that out, after watching it manually.

Hopefully that helps. It might be difficult to get it, but it can be done. And, like I said, it might be really simple.

Oh, yes, one last thing - if you know the location of the program, you can run "strings" against it and probably find out where it logs to from that output:

strings /full/path/to/dyyno

Best wishes,

Miek

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.