Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This script producing strange errors 3

Status
Not open for further replies.

AnotherAlan

Technical User
Feb 10, 2006
362
GB
Hi,

For the life of me I cannot work out why this is failing. Instead of the expected result of an email being fired everytime a line containing "failover" occurs it is instead randomly sending emails that lists the full contents of the directory from which the script is run i.e. as if I have piped ls -la into the /tmp/failover.log.
I have used constructs like this a number of times and they work as expected, the only difference being the tail binary.

Any ideas please, i'm seeing stars.
Thanks

Code:
LOG_DIR=/app/log2
LOG_FILE=b.log
NOTIFY_LIST="email"
/usr/xpg4/bin/tail -f -n0 $LOG_DIR/$LOG_FILE | while read line ; do

echo $line | awk '/failover/ {print $0}' > /tmp/failover.log

if [ -s /tmp/failover.log ]; then
        mailx -s "Failover Warning" $NOTIFY_LIST < /tmp/failover.log
fi

done
 
Hi

Alan said:
lists the full contents of the directory from which the script is run
Sounds like the $line contains an asterisk ( * ) which gets expanded by the shell. That is the price you have to pay if you not quote your variables. I mean the [tt]echo [green]"$line"[/green][/tt] .


Feherke.
 
This isn't your problem, but something you might want to watch. Try not to use variable names that are command names (try "[tt]man line[/tt]"). It's not a problem in your script, but sometimes it can cause some extremely weird behavior.


 
Just emphasize what Feherke noted:

As a rule I always always always double-quote my variables - especially in "if" conditions. Its rare that quoting will cause any grief.

A script that runs well, can suddenly break when the variable in the "if" condition contains a null string.

For example,

If [ $x = "1" ]; then ...

will work fine, until $x is null. This would cause the "if" to execute with this syntax:

if [ = "1" ]; then ...

Using quotes would execute like this:

if [ "" = "1" ]; then ...


 
Gave stars to ferherke & dkyrtata as this will help me correct a 3rd party script that does not like spaces in filenames & directorys.


I do not Have A.D.D. im just easily, Hey look a Squirrel!
 
I know it's the fashion, but I avoid spaces in filenames and directory names like the plague!

The internet - allowing those who don't know what they're talking about to have their say.
 
I try to avoid spaces as well

My problem was with the Xsane2Tesseract script which converts a scanner image to a tif file, passess it through the tesseract ocr enging and save save as a text file. I could not work out why it seemed to be failing for one particular usere (my dad as it happens) untill i realised he had a space in the name for his destination directory.

this post has given me the incentive to correct this particular script

I do not Have A.D.D. im just easily, Hey look a Squirrel!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top