| | |
passing a paramater to the log file
![]() |
•
•
Join Date: Jan 2009
Posts: 14
Reputation:
Solved Threads: 0
Shell Scripting Syntax (Toggle Plain Text)
#!/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
Last edited by Ancient Dragon; Jan 31st, 2009 at 8:42 am. Reason: add code tags
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
Hey there,
I'm sure what you're shooting for but, maybe:
or
Other than that, I'll need more specifics.
Best wishes,
Mike
I'm sure what you're shooting for but, maybe:
Shell Scripting Syntax (Toggle Plain Text)
LOG=${PROCS}.log $LOG "0"
or
Shell Scripting Syntax (Toggle Plain Text)
echo "0" >>$LOG
Other than that, I'll need more specifics.
Best wishes,
Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
•
•
Join Date: Jan 2009
Posts: 14
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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
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:
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:
Best wishes,
Miek

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
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'
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
Miek
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Other Threads in the Shell Scripting Forum
- Previous Thread: load-intensive shell script
- Next Thread: Packaging shell script
| Thread Tools | Search this Thread |





