![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|
#5
|
||||
|
||||
|
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
|
|||
|
|||
|
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
Neil added code tags for readability --oombera Last edited by oombera; 02-19-2004 at 09:08 AM. |
|||
| Google The UNIX and Linux Forums |