0

my requirement is as below:

i have a application server logs from which i need to grep for certain word say "hung" and restart the server if i found the word. i have written the script but there was a strange issue which is at first occurrence it finds and restarts the server but again after next interval of corn job it runs again and finds same word and keeps on restarting the server on every interval. how do i avoid this situation.

i want shell not to pick previously read message. can anyone help me on this

closed as unclear what you're asking by Scott, Romeo Ninov, Jeff Schaller, peterh, Anthony Geoghegan Oct 6 '17 at 13:18

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Yes, the word doesn't disappear from the log just because you restart the machine... – Kusalananda Oct 6 '17 at 9:54
  • You should look into using something like inotify integrated with tail -f for this. You can then action a script checking for certain data when the log is appended. – Raman Sailopal Oct 6 '17 at 9:57
  • @Kusalananda yeah thats what the issue is. any solution here? – Rajesh Oct 6 '17 at 10:09
  • Do the logs have a timestamp on each line? – Mark Plotnick Oct 6 '17 at 10:13
  • @MarkPlotnick yeah they do have time stamp – Rajesh Oct 6 '17 at 10:14
0

Have your script move the file to a different name just before restart. This way, you have a fresh, empty file at restart.

Say you're rebooting after finding the work in /var/log/app.log

Scritp ...

...
...

mv /var/log/app.log /var/log/app.lo.back
reboot
  • Alex, thanks for the suggestion and i believe this is the solution. infact i am trying to implement same solution and finding if my app server can do it for me. i.e., rotate the log when it restarts. – Rajesh Oct 6 '17 at 12:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.