The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
server restarting rcmrulzz SUN Solaris 4 06-05-2008 09:38 PM
restarting lpd service question Nayas UNIX for Dummies Questions & Answers 1 04-19-2008 07:02 AM
cannot telnet after restarting server wipi SUN Solaris 2 08-17-2007 02:57 AM
Restarting the Spooler Yorgy UNIX for Dummies Questions & Answers 0 09-29-2006 09:32 AM
Cron restarting problem vtran4270 UNIX for Dummies Questions & Answers 4 02-12-2004 10:33 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-17-2003
Registered User
 

Join Date: Aug 2002
Location: London, England
Posts: 84
Question restarting a while loop

I have a monitoring script that checks on the content of an alert file, I'm doing some checks on weather I have already reported on the alert (there is one alert per file). If I find that the content is the same as before how can I stop and restart the loop until there is differences bewteen the currect and previous log?

I was using a diff of two files and then trying to restart or continue depending on the status output (I had thought that break would do it but it exits from the loop).

Many fanks,

Neil

SunOS - ksh script
Forum Sponsor
  #2  
Old 07-17-2003
davidg's Avatar
Registered User
 

Join Date: Jul 2003
Location: Holland
Posts: 207
Hi Neil,

Please give us some scripto, it's confusing to get things clear right now.

Please be aware of logsurfer the tool that analyzes (growing) logfiles online and actiones as given patterns are matched.

I have it in production on 5 HP11.00 servers right now, and it's maybe the best tool I ever seen.


Regs David
  #3  
Old 07-25-2003
Registered User
 

Join Date: Aug 2002
Location: London, England
Posts: 84
This is the bit that I suspect is failing, this fits into my while loop (the loop filters, extract records from log files and prints to screen.. etc)

If the last and current log is the same then I want it to go back to the beginning of loop (the extarct and checks will start all over again). If its not the same then I want it to conitune with the rest of the loop. Hope this helps and you can help???!!!!


echo $FIELDS > new_alert.tmp

diff new_alert.tmp last_alert.tmp
if [ $? -eq 0 ]
then
echo No new alert messsages `date`
sleep 15
???????;
else
continue;
fi

David,
Looked at the Logsurf webiste, i'm not too sure if these will work on XML type files, what sort of files do you use it on?

Cheers,
Neil
  #4  
Old 07-25-2003
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Since you didn't post your whole script (or at least the complete while loop ), the isn't much I can say about it since it works as far as checking for differences and sleeping. The minute it finds a difference, then it runs an endless loop - making assumtions about how you have it set up as follows:
last_alert.tmp is set up the same as new_alert.tmp (tail of /var/adm/messages).
while it's running, I change last_alert.tmp to cause the program to go to the else statement.
Code:
#!/bin/ksh
tail /var/adm/messages > new_alert.tmp
while true
do
diff new_alert.tmp last_alert.tmp
if [ $? -eq 0 ]
then
        echo No new alert messages `date`
        sleep 15
else
        continue
fi
done
exit
You really need to give more information.
  #5  
Old 07-25-2003
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Hmm is this file going to be running all the time, every 15 seconds? Maybe you should set up a cron job.

If not, then try this:
Code:
changed="NO"

while [ $changed == "NO" ]; then
do
  echo $FIELDS > new_alert.tmp
  diff new_alert.tmp last_alert.tmp
  if [ $? -eq 0 ]; then
    echo No new alert messsages `date`
    sleep 15
    changed="YES"
  else
    continue
  fi
done
---------
Oh well, now you have two ways.
  #6  
Old 07-25-2003
Registered User
 

Join Date: Aug 2002
Location: London, England
Posts: 84
Hi there,

This is the complete loop, should have posted to begin with (doesn't give away any secrets). I did the 1 = 1 cos I just want it run for ever or until the user kills it. It checks if the error is new if not goes on to report on it on screen if it isn't I want it to recheck after a brief pause.
Code:
while [ 1 = 1 ]
do 

clear

integer EXT=1
ALERTDIR=/var/opt/projects/mnp/logs/alerts
CURRENTLOG=$ALERTDIR/alert.log.$EXT

# Moving on until a file is found
until [  -s $CURRENTLOG ] 
do
        EXT=`expr $EXT + 1`     
        CURRENTLOG=$ALERTDIR/alert.log.$EXT
done


# Makes the substitution of the fields in the alert logs.
FIELDS=`cat $CURRENTLOG | sed -e 's/">/, /g' \
             -e 's/<\/OBJECT>/, /g'  \
             -e 's/<//g'`

echo $FIELDS > new_alert.tmp

diff new_alert.tmp last_alert.tmp
        if [ $? -eq 0 ]
        then 
                echo No new alert messsages `date`
                sleep 15 
                ???????;
        else
                continue;
        fi

CODE=`echo $FIELDS | cut -f2 -d,`
DATE=`echo $FIELDS | cut -f4 -d,`


if [ $CODE = "T004" ]
then
        echo $FIELDS | cut -f2,4,12,15,17 -d, \
        \
        | awk -F"," '{print  ""; \
        print "ALERT ID   :" $1; \
        print "TIMESTAMP  :" $2; \
        print "ERROR CODE :" $3; \
        print "MSISDN     :" $4; \
        print "ERROR      :" $5}'

elif [ $CODE = "T002" ]
then
        echo $FIELDS | cut -f2,4,12,15,17 -d, \
        \
        | awk -F"," '{print ""; \
        print "ALERT ID   :" $1; \
        print "TIMESTAMP  :" $2; \
        print "ERROR CODE :" $3; \
        print "MSISDN     :" $4; \
        print "ERROR      :" $5}'

else 
        echo $FIELDS | cut -f2, -d, \
        \
        | awk -F"," '{print  ""; \
        print "ALERT ID   :" $1}' 
        echo "Unknown ERROR type, check with 3rd line"
fi

echo File `basename $CURRENTLOG`

cp new_alert.tmp last_alert.tmp
sleep 5
done
Many thanks is advance....

Neil

added code tags for readability --oombera

Last edited by oombera; 02-19-2004 at 09:08 AM.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0