Sponsored Content
Top Forums Shell Programming and Scripting How to calculate the time difference. Post 302248333 by manosubsulo on Friday 17th of October 2008 10:18:48 AM
Old 10-17-2008
Try this...

Code:
ssh -l ora${sid} ${primaryhost}  "awk '{print $3,$4,$5,$6}' /oracle/$ORACLE_SID/sapbackup/back$ORACLE_SID.log" | while read t1 t2 t3 t4
do
        tap1=`echo "$t1 $t2" | sed 's/[-/\.]/ /g'`
        tap2=`echo "$t3 $t4" | sed 's/[-/\.]/ /g'`
        echo $tap1
        echo $tap2
        nawk -f mk.awk -v _tm_test_1="$tap1" -v _tm_test_2="$tap2" >> ${RESULTFILE}
done
 
mk.awk:
----------
function Init()
{
        # Initialize table of month lengths
        _tm_months[0,1] = _tm_months[1,1] = 31
        _tm_months[0,2] = 28; _tm_months[1,2] = 29
        _tm_months[0,3] = _tm_months[1,3] = 31
        _tm_months[0,4] = _tm_months[1,4] = 30
        _tm_months[0,5] = _tm_months[1,5] = 31
        _tm_months[0,6] = _tm_months[1,6] = 30
        _tm_months[0,7] = _tm_months[1,7] = 31
        _tm_months[0,8] = _tm_months[1,8] = 31
        _tm_months[0,9] = _tm_months[1,9] = 30
        _tm_months[0,10] = _tm_months[1,10] = 31
        _tm_months[0,11] = _tm_months[1,11] = 30
        _tm_months[0,12] = _tm_months[1,12] = 31
}
# decide if a year is a leap year
function _tm_isleap(year,    ret)
{
        ret = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)
        return ret
}
# convert a date into seconds
function _tm_addup(a,    total, yearsecs, daysecs, hoursecs, i, j)
{
        hoursecs = 60 * 60
        daysecs = 24 * hoursecs
        yearsecs = 365 * daysecs
        total = (a[1] - 1970) * yearsecs
        # extra day for leap years
        for (i = 1970; i < a[1]; i++)
        if (_tm_isleap(i))
            total += daysecs
        j = _tm_isleap(a[1])
        for (i = 1; i < a[2]; i++)
        total += _tm_months[j, i] * daysecs
        total += (a[3] - 1) * daysecs
        total += a[4] * hoursecs
        total += a[5] * 60
        total += a[6]
        return total
}
# mktime --- convert a date into seconds, compensate for time zone
function mktime(str, res1, res2, a, b, i, j, t, diff)
{
        i = split(str, a, " ")    # don't rely on FS
        if (i != 6)
        return -1
        # force numeric
        for (j in a)
        a[j] += 0
        # validate
        if (a[1] < 1970 ||
        a[2] < 1 || a[2] > 12 ||
        a[3] < 1 || a[3] > 31 ||
        a[4] < 0 || a[4] > 23 ||
        a[5] < 0 || a[5] > 59 ||
        a[6] < 0 || a[6] > 60 )
            return -1
        res1 = _tm_addup(a)
        return res1
}
BEGIN  {
        Init()
        t = mktime(_tm_test_1)
        s = mktime(_tm_test_2)
        if (t != "-1" && s != "-1")
        {
                diff = s - t
                PerD=(24 * 60 * 60)
                DD = diff/PerD
                rem = (diff - (PerD * int(DD)))
                HH = rem / (60 * 60)
                mi = rem - (int(HH) * 60 * 60)
                MM = mi / 60
                SS = mi - (int(MM) * 60)
                printf("Time taken to Complete is %d Days %d Hour %d Minutes %d Seconds - Total Seconds %s\n", DD, HH, MM, SS, diff)
        }
        else
                print "Wrong Inputs.."
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to calculate this time difference

Hi, Please help me in calculating the time difference between below mentioned timestamps. a=07/17/2007 02:20:00 AM MST b=07/17/2007 02:07:46 AM MST Thanks (2 Replies)
Discussion started by: Prat007
2 Replies

2. Shell Programming and Scripting

How to calculate the time difference...

Hi All, I've written a script which reads all the systems backup information and saves it in a log file. ssh -l ora${sid} ${primaryhost} "tail -2 /oracle/$ORACLE_SID/sapbackup/back$ORACLE_SID.log" |head -1 | awk '{print echo "PREVIOUS:-- Start Date&Time: " $3,$4,echo "|| End Date&Time:... (1 Reply)
Discussion started by: suri.tyson
1 Replies

3. Shell Programming and Scripting

Formatting output so I can calculate time difference between two stamps

I know there have been a million questions regarding calculating time stamps, and with enough googling, I think I'm almost there (I'm going to use the changing the times into seconds and subtracting solution). My problem is that I'm not sure how to format my log file to get the info I need. Below... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

4. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

5. Shell Programming and Scripting

Calculate the Time stamp difference

hi, I have a log file which gives time stamps hh:mm:ss.sssss format in which hh- hours , mm -minutes ss.sssss - seconds.microseconds I need to calculate the time diff between sent time stamp and received time stamp .... could any one please help me.. i am tryin to write a script but... (2 Replies)
Discussion started by: firestar
2 Replies

6. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

7. Shell Programming and Scripting

Calculate time stamp difference

Hi All, I am new to shell scripting.I have to write a shell script for the problem statement: "A file is updated continously. If it is not updated for a day then an error message needs to pop up." So the script needs to read the last modified time of that file and current system time .If... (4 Replies)
Discussion started by: bharath.phatak
4 Replies

8. Shell Programming and Scripting

Calculate time difference between pst and pdt dates in perl

Hi, how to calculate the time difference between PST date and PDT date in perl scripting. date1: Mon Dec 31 16:00:01 PST 2015 date2: Tue Mar 19 06:09:30 PDT 2013 and also difference between PST-PST and PDT-PDT need difference in months or days (months prefereble). (3 Replies)
Discussion started by: praveen265
3 Replies

9. Shell Programming and Scripting

Calculate time difference

I have time in a file in HH:MM:SS format as it contents(its not the file creation time). i need this to be converted to epoch time or time since 1970. The time is written into that file by a script, which i cannot modify. Im using AIX machine $ cat abc.txt 10:29:34 (2 Replies)
Discussion started by: gpk_newbie
2 Replies

10. Shell Programming and Scripting

Calculate time difference between two lines

i grepped the time stamp in a file as given below now i need to calculate time difference file data: 18:29:10 22:15:50 (5 Replies)
Discussion started by: vivekn
5 Replies
BACKUPNINJA(1)							backupninja package						    BACKUPNINJA(1)

NAME
BACKUPNINJA - A lightweight, extensible meta-backup system "a silent flower blossom death strike to lost data." SYNOPSIS
backupninja [ -h ] [ -d ] [ -n ] [ -t ] [ -f filename ] [ --run filename ] DESCRIPTION
Backupninja allows you to coordinate system backups by dropping a few simple configuration files into /etc/backup.d/. Most programs you might use for making backups don't have their own configuration file format. Backupninja provides a centralized way to configure and coor- dinate many different backup utilities. FEATURES
- easy to read ini style configuration files. - you can drop in scripts to handle new types of backups. - backup actions can be scheduled. - you can choose when status report emails are mailed to you (always, on warning, on error, never). - console-based wizard (ninjahelper) makes it easy to create backup action configuration files. - passwords are never sent via the command line to helper programs. - in order to backup a db or sql database, you cannot simply copy database files. backupninja helps you safely export the data to a format which you can backup. - works with Linux-Vservers. Backup types include: - secure, remote, incremental filesytem backup (via rdiff-backup). incremental data is compressed. permissions are retained even with an unpriviledged backup user. - basic system and hardware information. - encrypted remote backups (via duplicity). - safe backup of MySQL, PostgreSQL, OpenLDAP, and subversion databases. - burn CD/DVDs or create ISOs. OPTIONS
-h, --help Show summary of options -d, --debug Run in debug mode, where all log messages are output to the current shell. -f, --conffile CONF_FILE Use CONF_FILE for the main configuration instead of /etc/backupninja.conf -t, --test Run in test mode, no actions are actually taken. -n, --now Perform actions now, instead of when they might be scheduled. --run ACTION_FILE Runs the action configuration ACTION_FILE and exits. CONFIGURATION
General settings are configured in /etc/backupninja.conf. In this file you can set the log level and change the default directory loca- tions. See backupninja.conf(5). To preform the actual backup actions, backupninja processes each action configuration file in /etc/backup.d according to the file's suffix. See backup.d(5). EXAMPLE USAGE
Backupninja can be used to implement whatever backup strategy you choose. It is intended, however, to be used like so: First, databases are safely copied or exported to /var/backups. Often, you cannot make a file backup of a database while it is in use, hence the need to use special tools to make a safe copy or export into /var/backups. Then, vital parts of the file system, including /var/backups, are nightly pushed to a remote, off-site, hard disk (using rdiff-backup). The local user is root, but the remote user is not privileged. Hopefully, the remote filesystem is encrypted. In order for this to work (ie for diff-backup to run unattended), you must create ssh keys on the source server and copy the public key to the remote user's authorized keys file. For example: root@srchost# ssh-keygen -t rsa -b 4096 root@srchost# ssh-copy-id -i /root/.ssh/id_dsa.pub backup@desthost Now, you should be able to ssh from user 'root' on srchost to user 'backup' on desthost without specifying a password. When prompted for a password by ssh-keygen, just leave it blank by hitting return. The "wizard" ninjahelper(1) will walk you through these steps. FILES
/usr/sbin/backupninja main script /etc/backupninja.conf main configuration file; general options /etc/cron.d/backupninja runs main script hourly /etc/logrotate.d/backupninja rotates backupninja.log /etc/backup.d directory for configuration files /usr/share/backupninja directory for handler scripts /usr/share/doc/backupninja/examples example action configuration files. SEE ALSO
ninjahelper(1), backupninja.conf(5), backup.d(5), AUTHOR
BACKUPNINJA was written by the riseup.net collective. riseup October 10, 2005 BACKUPNINJA(1)
All times are GMT -4. The time now is 03:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy