Find the answer to your Linux question:
Results 1 to 3 of 3
I'm writing a script that will automate the startup of a few services but some actions are dependent upon the successful completion of others. I can check for this by ...
  1. #1
    Linux Engineer Thrillhouse's Avatar
    Join Date
    Jun 2006
    Location
    Arlington, VA, USA
    Posts
    1,377

    Inspecting a log file until a certain message appears

    I'm writing a script that will automate the startup of a few services but some actions are dependent upon the successful completion of others. I can check for this by scanning the log file until the message I'm looking for appears but I can't seem to work this part into my script. I've tried:
    Code:
    while [ `tail -f /path/to/log/file | grep "PATTERN"` -ne "0" ]; do
    done
    just to idle until the correct message appears but it is just hanging forever even though I know the message has been written to the log.

    What's the best way to fix this?

  2. #2
    Linux Newbie
    Join Date
    Mar 2008
    Location
    Hyderabad
    Posts
    109
    I am guessing but your code looks like a tight busy loop.
    You should add some sleep. May be this is what is causing the hang.

  3. #3
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Location
    Tokyo, Japan
    Posts
    858
    you are asking to much to your box

    tail -f is meant to run foreground until you stop it, so if you put it in a while loop your computer will be like "wow its DoomsDay today!!". the instructions after tail -f wont run.

    you can use perl to avoid this though. perl will handle tail -f correctly so you wont have it hanging.
    Linux and me it's a love story

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...