The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep help flood Shell Programming and Scripting 3 06-06-2008 02:14 AM
Grep Aejaz UNIX for Advanced & Expert Users 3 04-30-2008 08:10 AM
grep dineshr85 Shell Programming and Scripting 1 10-10-2007 05:52 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 03:59 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 01:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-03-2008
appu1987 appu1987 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
Help grep and awk

I need to write a small shell script which does the following :

I have a file : root/var/log/ocmp/ocmpclient.log

This is a log file which is continuosly getting updated . I have to keep looking into this file all the time. I have to look for four keywords, "File Detected", File Sending", "File Recieved", "Disconnecting"

Now whenever i find one of these keywords i have to print them on the screen, this process continues till the computer shuts down.

Pls help me, I am supposed to use grep and awk

Help me its urgent.
  #2 (permalink)  
Old 06-04-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 167
How about

Code:
$ tail -f /root/var/log/ocmp/ocmpclient.log | grep 'File Detected\|File Sending\|File Recieved\|Disconnecting'
//Jadu
  #3 (permalink)  
Old 06-04-2008
appu1987 appu1987 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
tail -f /root/var/log/ocmp/ocmpclient.log | grep 'File Detected\|File Sending\|File Recieved\|Disconnecting'

I am using the above command now i want to write the output of this to go to a file output.txt
so i modified it as
#!/bin/sh
while true
do
tail -f /root/var/log/ocmp/ocmpclient.log | grep 'File Detected\|File Sending\|File Recieved\|Disconnecting' > output.txt
done


Now the problem is the file is created but doesnt contain anything.
  #4 (permalink)  
Old 06-04-2008
appu1987 appu1987 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 6
Quote:
Originally Posted by appu1987 View Post
tail -f /root/var/log/ocmp/ocmpclient.log | grep 'File Detected\|File Sending\|File Recieved\|Disconnecting'

I am using the above command now i want to write the output of this to go to a file output.txt
so i modified it as
#!/bin/sh
while true
do
tail -f /root/var/log/ocmp/ocmpclient.log | grep 'File Detected\|File Sending\|File Recieved\|Disconnecting' > output.txt
done


Now the problem is the file is created but doesnt contain anything.
Why is this happening
  #5 (permalink)  
Old 06-04-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
You don't need a while loop: "tail -f" is already an infinite loop until you manually terminate the process.

If you try:
Code:
tail -f file.log | grep "something" > output.txt
Your output file will remain empty until the grep buffer is flushed, which happens every "tot" bytes. If your grep version supports the option "--line-buffered" use it and you're done, otherwise you may need a while loop like:

Code:
tail -f file.log | while read LINE
do
   echo "$LINE" | grep "something" >> output.txt
done
Hope this helps.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

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




All times are GMT -4. The time now is 01:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0