script not working after "tail -f"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script not working after "tail -f"
# 1  
Old 07-01-2007
Network script not working after "tail -f"

Hi Everyone ,

I am facing a strange problem
i have made the follwing script to watch a appending log file (abc.log) but its not moving after the line tail -f ,
any suggestions

=====================================
#!/bin/bash
while true
do
tail -f abc.log | grep "exceptions"
echo hi
done
===================================

but the script keeps on giving the exceptions output as follows:

exception.TaxStrategyException: Error during port.getTax
exception.InterfaceException: Error MNP duplicate found
exception.CardPaymentException: Payment gateway rejected

and i want the out put to be as follows :------
exception.TaxStrategyException: Error during port.getTax
hi
exception.InterfaceException: Error MNP duplicate found
hi
exception.CardPaymentException: Payment gateway rejected
hi
================================================

the basic problem i have seen is that tail -f keeps on checking the appending log file due to which it doesnot ends up and the second command
echo hi never gets executed.

Please help me if there is any other way of doing this

Thanks
SmilieSmilie
# 2  
Old 07-01-2007
tail -f command ends only when killed.
The following script will give you the expected result :
Code:
#!/bin/bash
tail -f abc.log | grep "exceptions" |
while read line
do
   echo $line
   echo hi
done

But i'm not sure that it's what you really want to do.
# 3  
Old 07-01-2007
Aigles,

would below program work as well? I guess not the samething.. plus wastes the resource by going through the whole log everytime.. huh

string=exceptions

while [ -z "$string" ]
do
grep $string abc.log
sleep 2
done
echo hi
# 4  
Old 07-01-2007
Bug Many thanks !!!!! Aigles

Thanks Aigles
There seems that you have given me the solution to my problem;
however i have to go my office to try this technique .
i hope that your trick will solve my problem .
Thanks for the reply

Quote:
#!/bin/bash
tail -f abc.log | grep "exceptions" |
while read line
do
echo $line
echo hi
done
SmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilieSmilie
# 5  
Old 07-02-2007
Script not working

Smilie

Quote:
#!/bin/bash
tail -f abc.log | grep "exceptions" |
while read line
do
echo $line
echo hi
done

sorry to say that

the trick didnt work

because when i am using


Quote:
tail -f abc.log | grep "exception"|


after this line the cursor stops and doesnot give any output

but when i use only
tail -f abc.log | grep "exception"


it gives the output as exception

but is not read by the

while read line
do
echo $line
echo hi
done


As a result next lines of codes never get executed
is there any other way of doing this

thanx in advance
# 6  
Old 07-02-2007
It's a buffering problem. If you remove the grep command, all the lines will be processed inside the while loop.

The solution is to filter lines inside the while loop :

Code:
#!/bin/bash
tail -f abc.log | 
while read -r line
do
   [[ "$line" != *exceptions* ]] && continue
   echo $line
   echo hi
done

# 7  
Old 07-02-2007
MySQL Bravo Aigles !!!!!!!!!!! man you did it

Smilie

Many thanks to you My friend

You are really a man in the unix world

This time it worked

I really appreciate your help

Thankyou very much
SmilieSmilieSmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Beginners Questions & Answers

Automate "touch" bash script not working.

#!/bin/bash -i SAVEIFS=$IFS IFS=$"\n\b" picc=$* if ; then echo $TDATE if ; then touch dummy touch -t "tdate" dummy touch -r "dummy" "$picc" else echo -e "No mod date value to apply. If there is one in your shell,\ninvoke \eStarted asking advice on this (on Linuxquestions.org).... (9 Replies)
Discussion started by: iamwrong
9 Replies

3. Shell Programming and Scripting

"if" Loop not working when executing script using cron

I am facing this weird issue where the script is working fine from the command line but when I am executing it from cron though it is working fine but the "if" loop is processing else part though I know that the if part of the logic is true and ideally the loop should execute the if portion. ... (3 Replies)
Discussion started by: sk2code
3 Replies

4. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

5. UNIX for Dummies Questions & Answers

"tail -n 1 filename" error while "head -n 1 filename" is ok?

Hi all, I was wondering why tail -n 2 filename produce an error when I manage to do similar command on head -n 2 filename SunOS{type8code0}: tail -n 2 filename usage: tail ] tail ] (2 Replies)
Discussion started by: type8code0
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. UNIX for Dummies Questions & Answers

using "tail -f" in script

I am trying to use this script however it is not running well #!/bin/sh tail -f filename | grep -i -E 'error|warning' the code does not display the first 10 lines of the file that I want to check since after the file grow, it cannot grep "warning" as well #!/bin/sh A=`tail -f filename... (5 Replies)
Discussion started by: ikeQ
5 Replies

8. Shell Programming and Scripting

"sed" command is not working in shell script

Hi All, I am not much strong in shell scripting... I am using sed command in my script to find and replace a string....... This is how script looks : ############# #!/usr/bin/ksh CONFIG_FILE=iom_test.txt FIND=`echo "NIS_FTP_SERVER1=123.456.iom.com"` REPLACE=`echo... (2 Replies)
Discussion started by: askumarece
2 Replies

9. Shell Programming and Scripting

Script not working..."sort" not working properly....

Hello all, I have a file - 12.txt cat 12.txt =============================================== Number of executions = 2 Total execution time (sec.ms) = 0.009883 Number of executions = 8 Total execution time (sec.ms) = 0.001270 Number of... (23 Replies)
Discussion started by: Rahulpict
23 Replies

10. Shell Programming and Scripting

Perl - immitate perpetual "tail"

Is there some way I can have a script monitor the newest line of a log file until a certain entry gets placed in the log? Basically I want to start this script, and have it spit up the last 10 lines or so to a browser via AJAX... the AJAX is not my problem though, as I have no idea how to go... (4 Replies)
Discussion started by: jjinno
4 Replies
Login or Register to Ask a Question