need help in time manipulation

i have a script that gives the last time the data is inserted in a file. i want to check the time difference b/w the sytem time and the time in file.

for e,g.

if script runs at 3.30.So $a=3.30
and the time in file is 3.00.So $time =3.00

then the time difference should be 30 min......

-------------------------------------------------

#!/bin/ksh

a=`date +"%H:%M"`
cd /ednadtu3/u01/pipe/logs

Time=`ls -ltr File1.log | tr -s " " | cut -d " " -f8`

count=`expr $a - $Time`
if [ $count -gt 30 ]
then
echo "it is not processing data"
else
echo "it is processing data"
fi
--------------------------------------------------------------

so here if the delay b/w the time is More than 30 minutes,so it means it is not processing data
plz help me in this

Please clarify above DarkRed variables....

Sorry....... i have made the chnages in the script.....

now can u tell me how to get the time diff b/w the $a and $Time.

Use a perl function:

#!/bin/ksh
# filetimes compared with now 
filetimediff()
{
    perl  -e '
          use POSIX qw(strftime);
          
          $mtime = (stat $ARGV[0])[9];             
          $seconds1 = strftime "%s\n", localtime($mtime);
          $seconds = time;
          $seconds -= $seconds1;
          print "$seconds: ";         # total seconds comment out if not needed
          $hours = int $seconds / 3600 ;
          $minutes = int ($seconds - (3600 * $hours)) / 60;
          $seconds = $seconds % 60;
          # print HOURS:Minutes:Seconds,  comment out if not needed
          printf "%d:%02d:%02d\n", $hours, $minutes, $seconds; 
         ' $1
}
#usage example
dt=$(filetimediff  "$1")
echo "$dt"

Here is a ksh function which converts a time to seconds passed since midnight. From there on it is simply a matter of integer arithmetic.

# ------------------------------------------------------------------------------
# f_ConvertTime                        converts timestrings to seconds since MN
# ------------------------------------------------------------------------------
# Author.....: Wolf Machowitsch
# last update: 2005 05 15    by: Wolf Machowitsch
# ------------------------------------------------------------------------------
# Revision Log:
# - 0.99   2005 05 15   Original Creation
#                       base functionality, correction of incomplete
#                       timestrings like ":15" or "14"
#
# - 1.00   2007 11 20   Production release
#                       it was possible to pass nonsense data without
#                       f_ConvertTime() returning ERRLVL 1. This is
#                       now fixed. "f_ConvertTime aksj:00" will give
#                       back 1 as return value.
#
# ------------------------------------------------------------------------------
# Usage:
#     f_ConvertTime <char> timestring -> <int> seconds
#
#     Example: iSecondsSinceMidnight=$(f_ConvertTime "10:00:00")
#              print - $iSecondsSinceMidnight       # yields "36000"
#
# Prerequisites:
#
# ------------------------------------------------------------------------------
# Documentation:
#     f_ConvertTime() gets a timestring in $1 and prints the number of
#     seconds elapsed since midnight up to this time to <stdout>.
#     "Timestring" is any string of up to 3 digit groups delimited by
#     a non-digit separator. Digit groups amounting to "0" can be omitted
#     as can trailing separators, therefore "10:00:00", "10:00" and "10"
#     are treated the same, as well as "10-00.00", etc..
#
#     "00:10:01" can also be written ":00:01" and "10::10" and "10:00:10"
#     will both result in 36010.
#
#     Parameters: char Timestring
#     returns:    0 = no error
#                 1 = parameter error, minutes > 60, etc.
#                >1 = miscellaneous error
#                 Result is printed to <stdout>
#
# ------------------------------------------------------------------------------
# known bugs:
#
#     none
# ------------------------------------------------------------------------------
# ......................(C) 2005 Wolf Machowitsch ..............................
# ------------------------------------------------------------------------------

f_ConvertTime ()
{

typeset -i iRetVal=0
typeset    chTime="$1"
typeset -i iHours=0
typeset -i iMinutes=0
typeset -i iSeconds=0
typeset -i iTimeSecs=0

$chFullDebug
                                                 # correct timestring
chTime="$(print - "$chTime" | sed 's/[^0-9]/:/g')" # 14.15.00 -> 14:15:00
chTime="00${chTime}:00:00"                       # 14 -> 14:00:00
                                                 # :15 -> 00:15:00:00
if [ "$(print - $chTime | cut -d':' -f1)" != "" ] ; then
     iHours=$(print - $chTime | cut -d':' -f1)
     if [ $iHours -lt 0 -o $iHours -gt 23 ] ; then
          iRetVal=1
     fi
else
     iRetVal=1
fi
if [ "$(print - $chTime | cut -d':' -f2)" != "" ] ; then
     iMinutes=$(print - $chTime | cut -d':' -f2)
     if [ $iMinutes -lt 0 -o $iMinutes -gt 59 ] ; then
          iRetVal=1
     fi
else
     iRetVal=1
fi
if [ "$(print - $chTime | cut -d':' -f3)" != "" ] ; then
     iSeconds=$(print - $chTime | cut -d':' -f3)
     if [ $iSeconds -lt 0 -o $iSeconds -gt 59 ] ; then
          iRetVal=1
     fi
else
     iRetVal=1
fi
(( iTimeSecs = iSeconds + iMinutes * 60 + iHours * 3600 ))

print - $iTimeSecs

return $iRetVal
}

# --- EOF f_ConvertTime

I hope this helps.

bakunin

thanks i got it now..............thank you very much for ur help. i really appreciate it

Here's a quick-and-dirty Python version. Obviously you wouldn't hard-code the filename, but here it is.

 $ cat timeDiff.py 
#!/usr/bin/env python


import time #time functions
import os #os-specific functions

system_time = time.time()

file = "temp.txt"
    
if os.path.isfile(file):

    last_modified = os.path.getmtime(file)
        
timeDiff = (system_time - last_modified) / 60
print "System time: %s. Last modified, %s. %0.2f minutes." % (system_time, last_modified, timeDiff)