943,959 Members | Top Members by Rank

Ad:
Jan 29th, 2009
0

passing a paramater to the log file

Expand Post »
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. # Days and Procs declaration
  3. DAYS="3"
  4. PROCS="dyyno"
  5.  
  6. # 3 days Old date
  7. AGO=$(date --date="$DAYS days ago" +"%b %d")
  8.  
  9. # Getting pids
  10. PIDS=$(ps eaxo bsdstart,cmd,pid | egrep "^$AGO"' | egrep "$PROCS" | awk '{ print $4}')
  11.  
  12. # killing the processes
  13. echo "Killing $PROCS process created $AGO days ago"
  14. kill -9 $PIDS
  15.  


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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madurai07 is offline Offline
14 posts
since Jan 2009
Jan 29th, 2009
0

Re: passing a paramater to the log file

Hey there,

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

Shell Scripting Syntax (Toggle Plain Text)
  1. LOG=${PROCS}.log
  2.  
  3. $LOG "0"

or

Shell Scripting Syntax (Toggle Plain Text)
  1. echo "0" >>$LOG

Other than that, I'll need more specifics.

Best wishes,

Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007
Jan 30th, 2009
0

Re: passing a paramater to the log file

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
madurai07 is offline Offline
14 posts
since Jan 2009
Jan 31st, 2009
0

Re: passing a paramater to the log file

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

Quote ...
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:

Quote ...
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:

Quote ...
strings /full/path/to/dyyno
Best wishes,

Miek
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: load-intensive shell script
Next Thread in Shell Scripting Forum Timeline: Packaging shell script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC