restarting a while loop


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers restarting a while loop
# 1  
Old 07-17-2003
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 Smilie
# 2  
Old 07-17-2003
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
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
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
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. Smilie
# 6  
Old 07-25-2003
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 12:08 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SuSE

Restarting syslog-ng

Environment: SUSE 10.3 I made a configuration change in '/etc/syslog-ng/syslog-ng.conf' file in a server. An article found on web says "After the change '/etc/init.d/syslog-ng' should be restarted". But there is no 'syslog-ng' in /etc/init.d directory. What is syslog-ng or a... (4 Replies)
Discussion started by: JDBA
4 Replies

2. Shell Programming and Scripting

Need help in restarting process

Hi friends, I have one unix command which is used to check the network status manually. followig is the command check_Network this command give follwoing status Network 1 is ok Network 2 is ok network 3 is ok network 4 is ok . . . . Network 10 is... (8 Replies)
Discussion started by: Nakul_sh
8 Replies

3. UNIX for Dummies Questions & Answers

Restarting a process

Hi, How is it possible to restart only your process. I can get the process killed but I am not able to start it. For eg : i first did this ps -ef|grep _out --displays all the process with _out in the name then I killed kill -15 36044 -- process id. Now how can i start the same... (1 Reply)
Discussion started by: TH3M0Nk
1 Replies

4. Programming

Restarting the program

Hi, I use gfortran to run the code. Some times I need to stop the program and restart it. On restarting I need to run the program from the beginning. Is there any script or option available to restart the program from where it stopped? This script/option will be immensely useful for... (2 Replies)
Discussion started by: rpd25
2 Replies

5. Solaris

Restarting syslogd on Unix

Hi All, I can seem to find the syslog daemon in the /etc/init.d/ dir. i have made change to the syslog.conf i need to restart the daemon. am using solaris 10. i have no problem on version 9 Anyone with a template i can use for log review for auditing purposes. (1 Reply)
Discussion started by: lottiem
1 Replies

6. Solaris

server restarting

Hello people, My solaris server is rebooting, not sure how!!! Which log should I look in to? I checked /var/adm/messages and dmesg also. How do I check older dmesg logs? I checked lastlog and also ran the last command. Nothing useful pointing to why server rebooted. Also when server reboots I... (4 Replies)
Discussion started by: rcmrulzz
4 Replies

7. SCO

System restarting itself every after 20-24 hours

HI We have Compaq ML350 G2 server with UNIX SCO 5.0.5 OS , can anyone help us to get rid about the system restarting problem by itself every after2-24 hours with following error " MEMORY CORE DUMP " . Waiting for your ASAP help. Thank You . (4 Replies)
Discussion started by: munirh
4 Replies

8. UNIX for Advanced & Expert Users

How to solve restarting problem

Hi! My unix os version is OSF1 CP1 V4.0 878 alpha. It startup normally but it restarts within 5 sec. I would like to know how to solve . Please reply to me. Thanks . akzin (2 Replies)
Discussion started by: akzin
2 Replies

9. UNIX for Dummies Questions & Answers

Restarting the Spooler

:confused: Everytime our UNIXWARE 7 Server is restarted we also have to restart the spooler. If the spooler is not restarted, print jobs get stuck in the queu. Once restarted by using the following command lpstop and lpstart everything works fine. Does anyone have any ideas what could be causing... (0 Replies)
Discussion started by: Yorgy
0 Replies

10. Shell Programming and Scripting

Restarting a Crashed Process

Hello, I host a couple of Call of Duty gameing servers. There are some hackers who love the crash them. When they crash them it simply causes a segmentaion fault and kills the PID. I was wondering it you could help me write a script to simply restart the program after it has been crashed. The... (9 Replies)
Discussion started by: Phobos
9 Replies
Login or Register to Ask a Question