Operating System - HP-UX
1827808 Members
10757 Online
109969 Solutions
New Discussion

Re: Simple Unix script (bourne/Korne) Needed!

 
SOLVED
Go to solution
Shaun Aldrich_1
Advisor

Simple Unix script (bourne/Korne) Needed!

All:

I need a simple UNIX script (Bourne/Korne/Tcsh) that someone might have already done or would know how to do with the following requirements:

The script would run every 10 or 15 minutes and look inside a certain application log for the following strings:

2003/06/08 20:08:52 :MGR ,26317:6501 [-07832 Incremental database backup completed successfully.] : Log :

2003/06/08 20:14:13 :MGR ,26317:6501 [-07832 Incremental database backup completed successfully.] : Log :

2003/06/08 20:19:44 :MGR ,26317:6501 [-07832 Incremental database backup completed successfully.] : Log :

I will also attach a sample of the log since the above does not show up on a single line.

The Incremental database backup completed successfully messages show up every 5 or 6 minute intervals as shown above which indicates that there are no problems.

The script will check the log file for the latest [-07832 Incremental database backup completed successfully.] & compare the message date and time time to the current date and time. If no new incremental successful message is in the log within a 10 minute period then it will send an opcmsg (ITO Alert) stating that the incremental backup failed.

I thought a command like this could be used somewhere in the script:

# cat oracle.log-0 | grep "Incremental database backup completed successfully" | tail -1

2003/06/08 20:19:44 :MGR ,26317:6501 [-07832 Incremental database backup completed successfully.] : Log :

Any help someone could provide would be greatly appreciated as I know there are individuals within the forums here who are very good at scripting.

Look forward to hearing from you.

Thanks...
Hard work & dedication goes a long way...
11 REPLIES 11
Dario_1
Trusted Contributor

Re: Simple Unix script (bourne/Korne) Needed!

Hi Shaun:

Is this a duplicated question or none of the answers given yesterday worked for you?

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x97ab44f56197d711abdc0090277a778c,00.html

Thx,

Dario
John Meissner
Esteemed Contributor

Re: Simple Unix script (bourne/Korne) Needed!

didn't you already post this question:

http://bizforums.itrc.hp.com/cm/QuestionAnswer/1,,0x97ab44f56197d711abdc0090277a778c,00.html

in any case...
The following script may need some minor modifications to excape any special characters in the sed statements.



#! /usr/bin/ksh
x=1
while x=1
do
cat logfile | grep 07832 Incremental database backup completed successfully.] : Log : >> newlogfile
cat logfile | sed 's/07832 Incremental database backup completed successfully.] : Log : //#07832 Incremental database backup completed successfully.] : Log : /g' > logfile2
mv logfile2 logfile
sleep 600
done
All paths lead to destiny
Shaun Aldrich_1
Advisor

Re: Simple Unix script (bourne/Korne) Needed!

Unfortunately I was unable to use any of the script suggestions provided in yesterday's posting.

The actual script which would run in cron would check the log file for the latest [-07832 Incremental database backup completed successfully.] message & compare the message date and time time to the current sytem date and time. If no new incremental successful message is in the log within a 10 minute period then it will send an opcmsg (ITO Alert) stating that the incremental backup failed.

Thanks in advance for your help...
Hard work & dedication goes a long way...
Donny Jekels
Respected Contributor

Re: Simple Unix script (bourne/Korne) Needed!

Shaun,

we gave you ideas on how to get started. If you wanted us to write the entire thing for you, then all you to do is ask.

there is a lot of nice people on the forum

peace
Donny
"Vision, is the art of seeing the invisible"
John Meissner
Esteemed Contributor

Re: Simple Unix script (bourne/Korne) Needed!

This script may steer you in the right direction


x=1
while x=1
do
time=$(date +'%Y/%m/%d %H:%M:%S')
min=$(echo $time | awk -F: '{print $2}'
((ttime=$min-10))
day=$(date +'%d')
year=$(date +'%Y')
month=$(date +'%m')

#bs gets all successful backups from today
bs=$(cat file | grep $year | grep $month | grep $day | grep "Incremental database backup completed successfully")

bstime=$(echo $bs | awk -F: '{print $2}')

#finds 10 or less time difference
((timediff=$time-$bstime))
if [ $timediff <= 10 then ]
echo $bs > logfile
else
#whatever actions to send alert
fi
sleep 600
done
All paths lead to destiny
John Meissner
Esteemed Contributor

Re: Simple Unix script (bourne/Korne) Needed!

sorry about my above syntax errors

if [ $"timediff <= 10 then]
should be
if [$"timediff <= 10 ]
then

- i tend to think faster than I type sometimes.

Glad to see that this was helpful though
All paths lead to destiny
Shannon Petry
Honored Contributor

Re: Simple Unix script (bourne/Korne) Needed!

Muling this over for a day, leads me to several concerns about what your trying to do.

Firs off, are you really looking for failures or only success? IMHO kind of silly to look for success, when the log already shows that. I guess you could want it for reporting, but what your getting out is not of much value to a report.

Second, you say you want it to run every 10 or 15 minutes in cron. How does your application schedule this? What happens if your app runs 2 increments in the time the cron job runs 1 time? Or what happens if the increment does not change within 2 cron jobs?

Backups are usually dependant on external issues themselves, so writing a time dependant script when you have an I/O dependant application is not the best way to handle tracking, logging, or reporting, and in fact depending on what your doing this could be a nice shot to the foot.

I'd recommend you make a wrapper for the backup script itself, intercept it's output and re-direct it where you need it to go.

Next step is to have someone code a daemon that monitors the log for changes, then acts on the changes only.

If neither of those 2 are possible, talk to the software vendor to see if there is any way you can control the output going to the log. Many 3rd party vendors are happy to work with you.


If none of the samples given work out of the site, it's because were here as students and teachers, not sub-contracters. Consider hiring a consultant for a day. Really, we need to eat too! ;)

Sincerely,
Shannon Petry
Microsoft. When do you want a virus today?
F. X. de Montgolfier
Valued Contributor

Re: Simple Unix script (bourne/Korne) Needed!

Hi Shaun,

a very simple solution:
# --- start of the script here
#!/usr/bin/ksh
# first, let's count the number of times the log message appears in the log file
# don't forget to cd to the correct directory
let i=`/usr/bin/grep -c "[-07832 Incremental database backup completed successfully.]" oracle0.log`
# then let's sleep 10 minutes
sleep 600
# let's count the new number of occurences for the message
let j=`grep -c "[-07832 Incremental database backup completed successfully.]" oracle0.log`

# if j is not strictly greater than i, you have a problem...
if [ $j -le $i ]
do
# put your ITO alert here
done

# end of the script

Cheers,

FiX



Shaun Aldrich_1
Advisor

Re: Simple Unix script (bourne/Korne) Needed!

Thanks everyone for your suggestions...

I will be testing the various scripts today.

Everyone in these forums is of great assistance. Scripting is my current weakness but an area which I am working on improving.

Regards,

Shaun
Hard work & dedication goes a long way...
F. X. de Montgolfier
Valued Contributor
Solution

Re: Simple Unix script (bourne/Korne) Needed!

Aaargh!
Sorry, Shaun, I made quite a stoopid mistake in the script I wrote...

when I wrote:
---
if [ $j -le $i ]
do
# put your ITO alert here
done
---


I, of course, meant:
---
if [ $j -le $i ]
then
# put your ITO alert here
fi
---

It's, of course, "if [] then [] fi"...

Sorry about that...

FiX



Shaun Aldrich_1
Advisor

Re: Simple Unix script (bourne/Korne) Needed!

Thanks for your assistance...
Hard work & dedication goes a long way...