I"m trying to calculate the duration of of backup within a ksh shell script but I get an error.
#!/bin/ksh
STTIM=`date '+%T'`
EDTIM=`date '+%T'`
....
....
echo "DURATION OF BACKUP: $((EDTIM - STTIM))"
I"m trying to calculate the duration of of backup within a ksh shell script but I get an error.
#!/bin/ksh
STTIM=`date '+%T'`
EDTIM=`date '+%T'`
....
....
echo "DURATION OF BACKUP: $((EDTIM - STTIM))"
you are missing the "$"
echo "DURATION OF BACKUP: $(($EDTIM - $STTIM))"
--ahamed
%T gives you HH:MM:SS, which being a string, can't have arithmetic done on it.
Try %s, which will be seconds in epoch time.
---------- Post updated at 12:53 PM ---------- Previous update was at 12:52 PM ----------
No he's not. $(( )) do not require variables to have a $.
Just figured out, it works without "$" also.
So whats the error you are getting?
--ahamed
---------- Post updated at 11:54 AM ---------- Previous update was at 11:53 AM ----------
ahhh my bad... sorry!
--ahamed
When I replaced %T with %s I got 0
DURATION OF BACKUP: 0
COMPRESSING OF FILES STARTING
DURATION OF COMPRESSING FILES: 0
This ran well over 6 minutes.
I don't know what the problem is.
You put both date calls the beginning of the script -- they get the exact same time, and the difference is zero.
Put one at the end instead.
Depending on your shell, you might be able to skip all this and just use the special SECONDS variable. echo "script has been running ${SECONDS} seconds"