This is how my log file looks like:

2019-03-17 13:49:01.267 MESSAGE Web  
2019-03-17 13:50:04.325 ERROR error msg: ConnectivityException  
2019-03-17 14:15:20.326 ERROR error msg: Error occurred invoking AgentConnector.call() method  
2019-03-17 14:30:30.326 WARNING start: Web  
2019-03-17 14:49:12.327 ERROR exec-10 - null  

I have to read through this log every 5 mins and catch any error happened during last 5 mins i.e when I read this log at 14:16 pm, I should only get 1 error, which happened at 14:15 but not 13:50 pm error. My script exits at every run.

I read we can do this using "dd" but I m not getting it to write in a script form.

dd if="$in_file" iflag=skip_bytes,count_bytes,fullblock bs="$block_size" skip="$start" count="$copy_size"  

Any other way to get this done.

  • i hope we should check past 5 mins log instead of next 5mins... – msp9011 Mar 20 at 12:39

You can try to set cron job to look for error, perform following:

  1. Create script to tail lines from the error file to get the latest error.
  2. Then pipe the output with "Error".
  3. Add the script in cron (*/5 * * * * PATH_TO_SCRIPT)
  • 1
    I guess you mean */5. How does this only yield errors that happened in the last 5 minutes, though? – DonHolgo Mar 20 at 13:30
  • correct @DonHolgo – Vivek Kanadiya Mar 20 at 13:36
  • No , error can vary time to time – Machine Mar 20 at 13:36
  • Any other solution ? Above tail solution doesnot seem to be working . How do we tick what we have read before and what we will read in current run ?Please help with other solutions – Machine Mar 21 at 13:42
  • You can add tail -F which will tail the current file. – Vivek Kanadiya Mar 21 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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