Shell script to monitor the log file & kill the process if log is not updating.
Hi Everyone,
Can anyone help me to write a script to monitor the log file after every 10 mins & if the log file is not updating then kill the particular process by name. Your early response will be highly appreciated. |
Quote:
Code:
logmtr(){ |
@porphyry5: instead of just comparing the contents of the file, I would suggest to use stat and remember the last modification time of the file.
Another way of implementing it, could be an application where you set an alarm(600); which you trap and to reset the timer by an inotify() when the file is modified. |
Quote:
Code:
newln=$(tail -1 log.txt) Code:
newln=$(stat log.txt | grep Modify) |
Thanks everyone for their valuable inputs.
With your inputs & search on google I made smalll scripts & its working for me..... ----------------------------------------------- if test `find "/mylogfilepath" -mmin +10` then echo old enough kill -9 `pgrep ProcessName` fi ----------------------------------------------- Pls reply me with your valuable suggestions. |
Quote:
If you use kill first, wait a little and if the app is still active then use kill -9, it might save some grief. Also, grep returns a list of everything that matches its argument, so if there is more than one instance running of the app you want to shut down, it will return a list of them all. I don't know how kill reacts to receiving a list, but if its like other linux commands, it will kill every instance on the list, not just one of them. |
All times are GMT -5. The time now is 09:56 AM. |