0

I am writing a bash to monitor a logfile and would like to do something real quick after hitting certain line, some how it takes probably 6-8s to respond the <do_something>, anyway i could increase the responsive of my script? Here's my script

#!/bin/bash

tail -f screenlog.0 | while read LOGLINE
do
   [[ "${LOGLINE}" == *"Restarting system"* ]] && <do_something>
   if [ $? == 0 ]
   then
        break
   fi
done

Please advise any improvement or perhaps this can be done with 1 line command? Thanks

hellojoshhhy
  • 855
  • 2
  • 15
  • 32
  • I don't have an answer to your problem, but just a random thought. I guess whatever is generating the log file is writing to the disk and you are using your script to read from it. I don't know if this necessarily causes a delay of 6-8 seconds, but maybe it accounts for part of it. If you can think of a way to pipe the output of the program directly to your script, then maybe the I/O time can be bypassed? – Ray Aug 24 '20 at 04:17
  • 1
    https://stackoverflow.com/q/56675613 – alecxs Aug 24 '20 at 04:20
  • 2
    Maybe this is what you're looking for: [turn off buffering in pipe](https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe) – paddy Aug 24 '20 at 04:56

0 Answers0