Unix Shell - Calculating End Date and time, if the script aborts

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2006 > Calculating End Date and time, if the script aborts





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Calculating End Date and time, if the script aborts
BN

2006-12-20, 7:21 pm

Greetings,

I am writing a Kshell script for hp-ux, aix, sun to insert into
database,
the start_date_time, end_date_time, status from the backup log files.

If the backup is successful , I am able to get the end_date_time, BUT
if for some reason backup aborted, I have no idea on how to get the
end_date_time.

Here is the output of the log file when backup aborted:

Backup started 12/19/2006 23:02:34

23:02:35 Initiating backup
23:02:45 INF - Processing /bu1/orabk/mydb
23:02:45 /
23:02:45 /bu1/
23:02:45 /bu1/orabk/
23:02:45 /bu1/orabk/vrwcdb/
23:02:45 /bu1/orabk/vrwcdb/db/
23:02:45 /bu1/orabk/vrwcdb/db/current/
23:02:47 INF - Waiting for mount of media id
.. . . . .. . . .

02:01:47 INF - Waiting for mount of media id S06272 on server vrttds02
for writing.
02:31:42 ERR - Timed out waiting for the media to be mounted and
positioned.
02:31:42 ERR - Timed out waiting for the media to be mounted and
positioned.
02:31:46 ERR - bpbkar exiting because backup is aborting
02:31:46 ERR - bpbkar killed by SIGPIPE
Program is:/apps/opt/oracle/dbascripts/rman/bk2tape_db.ksh exit status
is:52

The last time stamp is at 02:31:46 which is next day, since the backup
has started at 23:02:35

so the
start_date_time="12/19/2006 23:02:34"
end_date_time = "12/20/2006 02:31:46"

The Backup need not have to start at 23:06:35 every day, some times it
can start after 00:00 hrs
some thing like 01:05:02 and ends the same day.

so the
start_date_time="12/20/2006 01:05:02"
end_date_time = "12/20/2006 03:31:46"


How can I do this.

Regards & thanks
BN

Janis Papanagnou

2006-12-21, 1:29 am

BN wrote:
> Greetings,
>
> I am writing a Kshell script for hp-ux, aix, sun to insert into
> database,
> the start_date_time, end_date_time, status from the backup log files.
>
> If the backup is successful , I am able to get the end_date_time, BUT
> if for some reason backup aborted, I have no idea on how to get the
> end_date_time.


Just print the start and end date before resp. after you call your
backup program...

echo Startdate: $(date)
do_DB_backup
echo Enddate: $(date)

Or make clear what your problem could be.

Janis

>
> Here is the output of the log file when backup aborted:
>
> Backup started 12/19/2006 23:02:34
>
> 23:02:35 Initiating backup
> 23:02:45 INF - Processing /bu1/orabk/mydb
> 23:02:45 /
> 23:02:45 /bu1/
> 23:02:45 /bu1/orabk/
> 23:02:45 /bu1/orabk/vrwcdb/
> 23:02:45 /bu1/orabk/vrwcdb/db/
> 23:02:45 /bu1/orabk/vrwcdb/db/current/
> 23:02:47 INF - Waiting for mount of media id
> . . . . .. . . .
>
> 02:01:47 INF - Waiting for mount of media id S06272 on server vrttds02
> for writing.
> 02:31:42 ERR - Timed out waiting for the media to be mounted and
> positioned.
> 02:31:42 ERR - Timed out waiting for the media to be mounted and
> positioned.
> 02:31:46 ERR - bpbkar exiting because backup is aborting
> 02:31:46 ERR - bpbkar killed by SIGPIPE
> Program is:/apps/opt/oracle/dbascripts/rman/bk2tape_db.ksh exit status
> is:52
>
> The last time stamp is at 02:31:46 which is next day, since the backup
> has started at 23:02:35
>
> so the
> start_date_time="12/19/2006 23:02:34"
> end_date_time = "12/20/2006 02:31:46"
>
> The Backup need not have to start at 23:06:35 every day, some times it
> can start after 00:00 hrs
> some thing like 01:05:02 and ends the same day.
>
> so the
> start_date_time="12/20/2006 01:05:02"
> end_date_time = "12/20/2006 03:31:46"
>
>
> How can I do this.
>
> Regards & thanks
> BN
>

Ed Morton

2006-12-21, 1:29 am

BN wrote:
> Greetings,
>
> I am writing a Kshell script for hp-ux, aix, sun to insert into
> database,
> the start_date_time, end_date_time, status from the backup log files.
>
> If the backup is successful , I am able to get the end_date_time, BUT
> if for some reason backup aborted, I have no idea on how to get the
> end_date_time.
>
> Here is the output of the log file when backup aborted:
>
> Backup started 12/19/2006 23:02:34
>
> 23:02:35 Initiating backup
> 23:02:45 INF - Processing /bu1/orabk/mydb
> 23:02:45 /
> 23:02:45 /bu1/
> 23:02:45 /bu1/orabk/
> 23:02:45 /bu1/orabk/vrwcdb/
> 23:02:45 /bu1/orabk/vrwcdb/db/
> 23:02:45 /bu1/orabk/vrwcdb/db/current/
> 23:02:47 INF - Waiting for mount of media id
> . . . . .. . . .
>
> 02:01:47 INF - Waiting for mount of media id S06272 on server vrttds02
> for writing.
> 02:31:42 ERR - Timed out waiting for the media to be mounted and
> positioned.
> 02:31:42 ERR - Timed out waiting for the media to be mounted and
> positioned.
> 02:31:46 ERR - bpbkar exiting because backup is aborting
> 02:31:46 ERR - bpbkar killed by SIGPIPE
> Program is:/apps/opt/oracle/dbascripts/rman/bk2tape_db.ksh exit status
> is:52
>
> The last time stamp is at 02:31:46 which is next day, since the backup
> has started at 23:02:35
>
> so the
> start_date_time="12/19/2006 23:02:34"
> end_date_time = "12/20/2006 02:31:46"
>
> The Backup need not have to start at 23:06:35 every day, some times it
> can start after 00:00 hrs
> some thing like 01:05:02 and ends the same day.
>
> so the
> start_date_time="12/20/2006 01:05:02"
> end_date_time = "12/20/2006 03:31:46"
>
>
> How can I do this.
>
> Regards & thanks
> BN
>


Using GNU awk and assuming it doesn't take more than a day for the
backup to complete:

$ cat file
Backup started 12/19/2006 23:02:34

23:02:35 Initiating backup
23:02:45 INF - Processing /bu1/orabk/mydb
23:02:45 /
23:02:45 /bu1/
23:02:45 /bu1/orabk/
23:02:45 /bu1/orabk/vrwcdb/
23:02:45 /bu1/orabk/vrwcdb/db/
23:02:45 /bu1/orabk/vrwcdb/db/current/
23:02:47 INF - Waiting for mount of media id
.. . . . .. . . .

02:01:47 INF - Waiting for mount of media id S06272...
02:31:42 ERR - Timed out waiting for the media to....
02:31:42 ERR - Timed out waiting for the media to...
02:31:46 ERR - bpbkar exiting because backup is aborting
02:31:46 ERR - bpbkar killed by SIGPIPE
Program is:/apps/opt/oracle/dbascripts/rman/bk2tape_db.ksh...
$
$
$ cat getdates.awk
/Backup started/ { startDate = $3; startTime = $4 }
$1 ~ /[0-9]/ { endTime = $1 }
END {
split(startDate":"startTime,a,/[:/]/)
startSecs = mktime(a[3]" "a[1]" "a[2]" "a[4]" "a[5]" "a[6])

split(startDate":"endTime,a,/[:/]/)
endSecs = mktime(a[3]" "a[1]" "a[2]" "a[4]" "a[5]" "a[6])

endDate = ( endSecs > startSecs ? startDate :
strftime("%m/%d/%Y",endSecs + 24 * 60 * 60) )

printf "Start Date/Time: %s %s\n",startDate,startTime
printf "End Date/Time : %s %s\n",endDate,endTime
}
$
$
$ awk -f getdates.awk file
Start Date/Time: 12/19/2006 23:02:34
End Date/Time : 12/20/2006 02:31:46
$

Regards,

Ed.
BN

2006-12-21, 7:31 am


Ed Morton wrote:
> BN wrote:
>
> Using GNU awk and assuming it doesn't take more than a day for the
> backup to complete:
>
> $ cat file
> Backup started 12/19/2006 23:02:34
>
> 23:02:35 Initiating backup
> 23:02:45 INF - Processing /bu1/orabk/mydb
> 23:02:45 /
> 23:02:45 /bu1/
> 23:02:45 /bu1/orabk/
> 23:02:45 /bu1/orabk/vrwcdb/
> 23:02:45 /bu1/orabk/vrwcdb/db/
> 23:02:45 /bu1/orabk/vrwcdb/db/current/
> 23:02:47 INF - Waiting for mount of media id
> . . . . .. . . .
>
> 02:01:47 INF - Waiting for mount of media id S06272...
> 02:31:42 ERR - Timed out waiting for the media to....
> 02:31:42 ERR - Timed out waiting for the media to...
> 02:31:46 ERR - bpbkar exiting because backup is aborting
> 02:31:46 ERR - bpbkar killed by SIGPIPE
> Program is:/apps/opt/oracle/dbascripts/rman/bk2tape_db.ksh...
> $
> $
> $ cat getdates.awk
> /Backup started/ { startDate = $3; startTime = $4 }
> $1 ~ /[0-9]/ { endTime = $1 }
> END {
> split(startDate":"startTime,a,/[:/]/)
> startSecs = mktime(a[3]" "a[1]" "a[2]" "a[4]" "a[5]" "a[6])
>
> split(startDate":"endTime,a,/[:/]/)
> endSecs = mktime(a[3]" "a[1]" "a[2]" "a[4]" "a[5]" "a[6])
>
> endDate = ( endSecs > startSecs ? startDate :
> strftime("%m/%d/%Y",endSecs + 24 * 60 * 60) )
>
> printf "Start Date/Time: %s %s\n",startDate,startTime
> printf "End Date/Time : %s %s\n",endDate,endTime
> }
> $
> $
> $ awk -f getdates.awk file
> Start Date/Time: 12/19/2006 23:02:34
> End Date/Time : 12/20/2006 02:31:46
> $
>
> Regards,
>
> Ed.


Greetings,

Thank you very much.

Why do you say
"assuming it doesn't take more than a day for the backup to complete:"

Is the Logic going to change?

If I cannot use gawk (not to have it on Production Servers - Company
Policy)
Is there any other way I can do this.

Regards & Thanks
BN

Ed Morton

2006-12-21, 1:20 pm

BN wrote:

> Ed Morton wrote:
>
>
>
> Greetings,
>
> Thank you very much.
>
> Why do you say
> "assuming it doesn't take more than a day for the backup to complete:"


Because I change the date to the next day if the originally calculated
end date/time appears to be earlier than the start date/time.

> Is the Logic going to change?


Yes. You'd need to check the timestamps all the way through the log file
looking for them rolling round N times to identify N days, and then
you'd be relying on there never being more than 24 hours between
timestamps in the file or there'd be no way to spot days being skipped.

> If I cannot use gawk (not to have it on Production Servers - Company
> Policy)
> Is there any other way I can do this.


Sure, write your own versions of mktime() and strftime().

Ed.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com