Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page Inspecting a log file until a certain message appears
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 05-15-2008   #1 (permalink)
Thrillhouse
Linux Engineer
 
Thrillhouse's Avatar
 
Join Date: Jun 2006
Location: Arlington, VA, USA
Posts: 1,174
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?
Thrillhouse is offline   Reply With Quote
Old 05-16-2008   #2 (permalink)
digvijay.gahlot
Just Joined!
 
Join Date: Mar 2008
Location: Hyderabad
Posts: 88
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.
digvijay.gahlot is offline   Reply With Quote
Old 05-17-2008   #3 (permalink)
khafa
Linux Enthusiast
 
khafa's Avatar
 
Join Date: Apr 2008
Location: Tokyo, Japan
Posts: 587
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
khafa is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 05:56 AM.

Powered by vBulletin 3.6.8 ©2000 - 2007, content relevant URLs by vBSEO, Property of Core Root.

Content Relevant URLs by vBSEO 3.0.0