script not working after "tail -f"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script not working after "tail -f"
# 8  
Old 07-02-2007
Lightbulb Little more help after this

Hi

Thank you very much !!!!!!!!!!!!

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

Now i want to further refine the output

as there are differrent kind of exception are received
with this code for example :
Quote:
output of your script gives
exception.InterfaceException: Error MNP duplicate found
hi
exception.InterfaceException: Error MNP duplicate found
hi
exception.InterfaceException: Error MNP duplicate found
hi
exception.InterfaceException: Error MNP duplicate found
hi
exception.CardPaymentException: Payment gateway rejected transaction
hi
exception.CardPaymentException: Payment gateway rejected transaction
hi
exception.CardPaymentException: Payment gateway rejected transaction
hi
exception.CardPaymentException: Failed to retrieve digital receipt from database
hi
exception.TaxStrategyException: Error during port.getTax(getTaxRequest)) Error
hi

Quote:
and if i want the out put to be such that only the following lines are furter filtered out of the above exceptions :-----

exception.CardPaymentException: Failed to retrieve digital receipt from database
hi
exception.TaxStrategyException: Error during port.getTax(getTaxRequest)) Error
hi

# 9  
Old 07-02-2007
Code:
[[ "$line" != *CardPaymentException* && "$line" != *TaxStrategyException* ]] && continue

# 10  
Old 07-02-2007
Aigles,

Can you please elaborate on

read -r option? Just read the definition and cannot understand why -r was used. thank you for your great work as always~



-r Backslash does not act as an escape character.
The backslash is considered to be part of the line. In
particular, a backslash-newline pair may not be used as a line
continuation.
Code:
#!/bin/bash
tail -f abc.log | 
while read -r line
do
   [[ "$line" != *exceptions* ]] && continue
   echo $line
   echo hi
done

# 11  
Old 07-02-2007
Lightbulb How to get negated output

Hi
First thanks to all the genious minds who share their knowledge on this platform .
Smilie
Now Further i would like to ask that in this code to filter out the exceptions
Quote:
output of script gives
exception.InterfaceException: Error MNP duplicate found
hi
exception.InterfaceException: Error MNP duplicate found
hi
exception.InterfaceException: Error MNP duplicate found
hi
exception.InterfaceException: Error MNP duplicate found
hi
exception.CardPaymentException: Payment gateway rejected transaction
hi
exception.CardPaymentException: Payment gateway rejected transaction
hi
exception.CardPaymentException: Payment gateway rejected transaction
hi
exception.CardPaymentException: Failed to retrieve digital receipt from database
hi
exception.TaxStrategyException: Error during port.getTax(getTaxRequest)) Error
hi
How can we negate the output i.e the code
Quote:
#!/bin/bash
tail -f abc.log |
while read -r line
do
[[ "$line" != *exceptions* ]] && continue
echo $line
echo hi
done
should give the output other than the above mentioned i.e after filtering out the above exceptions . it should display all the other kind of exceptions coming . for example output should be :
Quote:
exception.DatabaseException: Database error occured
hi
exception.DatabaseException: Database error occured -311
hi
exception.InterfaceException:Anu no found
hi
exception.InterfaceException: Error checking linked numbers, negative ani position
hi
exception.CardPaymentException: Error checking linked numbers, negative ani position
hi
exception.DatabaseException: Database error occured -311
hi
exception.DatabaseException: Database error occured
hi
exception.DatabaseException: Error checking linked numbers, negative ani position
hi
exception.TaxStrategyException: calculate tax failed
hi
Thanks Smilie

Last edited by xander; 07-03-2007 at 10:42 AM..
# 12  
Old 07-03-2007
Pleasde help if some suggestion is there

hi
Please help me if some valuable suggestion is there

Thanx in Advance
# 13  
Old 07-03-2007
I am not sure to understand what you want to do.
If you want to display exceptions only once, you can try something like that :
Code:
exc_file=exceptions.$$
trap "rm -f $exc_file" EXIT

touch $exc_file

tail -f abc.log |
while IFS= read -r line
do
   [[ "$line" != *exception* ]] && continue
   if ! grep -q "^$line\$" $exc_file
   then
      echo "$line" >> $exc_file
      echo "$line"
      echo "hi"
   fi
done

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