tail -f utilization
hi everybody,
i'm a principiant on linux system so excuse me for my following stupid question... i have a LOGFILE which i need to view as soon as the events come...moreover i need to apply a filter on the events now i use: tail -f LOGFILE | grep PATTERN the problem is that my LOGFILE has the following feature: DATE INFO1 INFO2 INFO3 INFO4 INFO5 but i need "tail" command presents me data in this way: DATE - INFO1 - INFO3 - INFO5 what's the command line i have to use? THANKS A LOT!!! |
Try this :
Quote:
|
Beware that you'll have a delayed output as the pipe processing is buffered.
|
I tried Agrouf suggestion:
tail -f LOGFILE | grep PATTERN | while read line do printf "$line - " done but i received this warning: line 3: printf: --: invalid option printf: usage: printf format [arguments] moreover....do you know how can i print only some lines? for example first, second and fifth? THANKS A LOT!! |
i tried this way:
tail -f LOGFILE|grep PATTERN|while {read line} { printf \n set lineCount 0 if {lineCount==0||lineCount==3||lineCount==4} then {printf "$line "} incr lineCount } but i receive this error: line 6: syntax error near unexpected token `}' line 6: `}' PLEASE, WHERE IS THE ERROR?!?!? thanks |
The error is in the use of curly braces {} to enclose the list of commands.
Change this: tail -f LOGFILE|grep PATTERN|while {read line} { printf \n set lineCount 0 if {lineCount==0||lineCount==3||lineCount==4} then {printf "$line "} incr lineCount } to this: tail -f LOGFILE|grep PATTERN|while {read line} do printf \n set lineCount 0 if {lineCount==0||lineCount==3||lineCount==4} then {printf "$line "} incr lineCount done |
no way, this is the error:
line 7: syntax error near unexpected token `done' line 7: `done' |
Are you using bash?
Anyway, try this : Quote:
|
I don't understand about the logfile feature you are talking about.
Could you post a portion of the logfile. Piping through grep or sed should filter out unwanted lines. Code:
DATE |
Quote:
That should be : tail -f LOGFILE|grep PATTERN|while read line do echo # set lineCount 0 ==> is it tcsh? lineCount=0 # bash style if [ $lineCount=0 -o $lineCount=3 -o $lineCount=4 ] then printf "%s " $line # may work with your printf? fi lineCount=$(expr $lineCount + 1) done I believe you are confusing C and bash... ? |
sorry,
but i don't know what's my shell how can i check it? thanks PS: i told you i'm a beginner... |
What is the output of :
grep $USER /etc/passwd | cut -d ":" -f 7 |
this is the output:
/bin/bash /sbin/nologin i tried last "Agrouf" suggestion but i received this kind of otuput: + printf '%s ' Date: 6/26/07 1:23:49 PM Date: 6/26/07 1:23:49 PM ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' + printf '%s ' Logname: NAME12 Logname: pippo ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' + printf '%s ' Logtype: TYPE12 Logtype: TYPE ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' + printf '%s ' LogUser: USER12 LogUser: USER ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' + printf '%s ' LogClient: CLIENT12 LogClient: CLIENT ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' + printf '%s ' LogServer: SERVER12 LogServer: SERVER ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' + printf '%s ' LogLife: LIFE12 LogLife: LIFE ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' + printf '%s ' LogContent: CONTENT12 LogContent: CONTENT ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' + printf '%s ' -- -- ++ expr 0 + 1 + lineCount=1 + read line + lineCount=0 + '[' 0=0 -o 0=3 -o 0=4 ']' i inserted an "echo off" command at the begin of the script but anything is changed... For "jschiwal": this is what my tail|grep returns to me; i need only lines 1, 3, 4 ... Date: 6/26/07 1:33:14 PM LogName: NAME1 Logtype: TYPE1 LogUser: USER1 LogClient: CLIENT1 LogServer: SERVER1 LogLife: LIFE1 LogContent: CONTENT1 -- Date: 6/26/07 1:33:15 PM LogName: NAME2 Logtype: TYPE2 LogUser: USER2 LogClient: CLIENT2 LogServer: SERVER2 LogLife: LIFE2 LogContent: CONTENT2 -- Date: 6/26/07 1:33:16 PM LogName: NAME3 Logtype: TYPE3 LogUser: USER3 LogClient: CLIENT3 LogServer: SERVER3 LogLife: LIFE3 LogContent: CONTENT3 ... |
to complete infos:
i need a logfile like this: ... Date: 6/26/07 1:33:14 PM - Logtype: TYPE1 - LogUser: USER1 Date: 6/26/07 1:33:15 PM - Logtype: TYPE2 - LogUser: USER2 Date: 6/26/07 1:33:16 PM - Logtype: TYPE3 - LogUser: USER3 ... |
what is the output of
Code:
grep ^$USER: /etc/passwd | cut -d ":" -f 7 try Code:
set +x Code:
tail | grep | awk 'NR%9==1||NR%9==3 {printf $0 " - "} NR%9==4 {printf $0 "\n"}' |
All times are GMT -5. The time now is 06:31 AM. |