time arithmetic


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users time arithmetic
# 1  
Old 11-28-2001
Data time arithmetic

Can anyone help please. I am writing a kourne shell script and I am unsure how to do the following:

I have extracted a time string from a logfile, and I have another time string I want to compare it to to see if it's later than the time I'm comparing with.

i.e. expectedSLA="23:00:00", actualDeliveryTime="22:40:00"

I try to do the following:

missedSLA="N"
if [ $actualDeliveryTime > $expectedSLA ]
then
missedSLA="Y"
fi

This always sets missedSLA to "Y". Isn't it supposed to compare using the decimal values of the string? How can I get the above process to work? What can I do? Any help would be greatly appreciated.

Many thanks,
# 2  
Old 11-28-2001
Looking at your code I couldn't believe that it would run at all. But I tried "echo aaa > bbb ccc" and sure enough I created a file called bbb with the contents "aaa ccc". I never knew you could inbed redirects in the middle of an argument list.

That's what you are doing with "if [ $a > $b ]". You should be creating an output file. The [ is just a normal unix command that expects it's last argument to be ]. In the early days of the bourne shell, it was a link to the test command and sat in /usr/bin. Later it became a built-in, but it still is a command. It never understood > as a comparison operator. There is a -gt but it only works on integers and will barf on your time format.

You don't want an integer compare, you want an ascii string compare. So switch to [[ which is a keyword rather than a command:
if [[ $a > $b ]]
should work fine.

And it's korn, not korne. Smilie
# 3  
Old 11-28-2001
thanks that works just fine.

cheers mate.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Arithmetic with bash

I need to divide the number of white spaces by total number of characters in a file using bash. I am able to get the number of white spaces correctly using: tr -cd < afile | wc -c I am also able to get the total number of characters using: wc -c afile How do I divide the first... (2 Replies)
Discussion started by: ngabrani
2 Replies

2. Shell Programming and Scripting

Need help with date arithmetic please

Hello fellow forum members, I wrote below piece of code to calculate the date after a given date - date=$DATE_FINAL declare -a max_month=(0 31 28 31 30 31 30 31 31 30 31 30 31) eval $(echo $date|sed 's!\(....\)\(..\)\(..\)!year=\1;month=\2;day=\3!') (( year4=year%4 )) (( year100=year%100... (9 Replies)
Discussion started by: ektubbe
9 Replies

3. Shell Programming and Scripting

Date and time Arithmetic

Hi, I need to process a file which contains below data. Usually the files contains both Start and Finish time. but for Few records, it contains only Start. For those records I need to add the finish line by adding 5 minutes to Start time. Started BBIDX Tue Jun 1 15:15:11 EDT 2010 292308... (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

4. Shell Programming and Scripting

csh arithmetic ?

Hello, Could someone explain how this one is possible: # @ x = 10 - 11 + 3 # echo $x -4 I know that writing script using csh is bad idea, but I need to write few lines. thanks Vilius (2 Replies)
Discussion started by: vilius
2 Replies

5. UNIX for Dummies Questions & Answers

Arithmetic: how to??

Hello all, I'd like to know how to perform arithmetic on multiple files. I have got many tab-delimited files. Each file contains about 2000 rows and 2000 columns. What I want to do is to to sum the values in each row & column in every file. The following explains what I want to do; ... (9 Replies)
Discussion started by: Muhammad Rahiz
9 Replies

6. UNIX for Dummies Questions & Answers

Arithmetic Operators

Hello, I have a list of 'inputs' and i want to convert those on the second list named 'Desired Outputs', but i don't know how to do it? Inputs Desired Outputs 1 2 94 4 276 8 369 10 464 12 ... (0 Replies)
Discussion started by: filda
0 Replies

7. Shell Programming and Scripting

arithmetic in tcsh

Yes I know tcsh sucks for scripting and arithmetic but I have to write a script for multiple users and they all use tcsh. I have this variable that I 'set' with but pulling numbers off of stings with set STUFF = `grep string file | awk command` Now I would like to add up the numbers that... (4 Replies)
Discussion started by: gobi
4 Replies

8. Shell Programming and Scripting

arithmetic in ksh

Helloo.. I am trying one very simple thing I could not find anything on google.. I have 2 integer variable..and I need to do division...in ksh where $catch and $num are integer variable.. I tryed with this: printf "%0.2f" $final=$catch/$num but it does not work.. any help is... (12 Replies)
Discussion started by: amon
12 Replies

9. UNIX for Dummies Questions & Answers

Arithmetic In UNIX

I am a beginner and I have been searching the web all morning for this answer but can't find it anywhere. I know that prtint 1*2 will return 1*2 what if i actually want the problem to be calculated so i want print 1*2 to return 2 How is this done? (3 Replies)
Discussion started by: tygun
3 Replies

10. UNIX for Dummies Questions & Answers

arithmetic problem

i am used to making scripts for hp-ux. but lately i tried to make some for solaris. the problem is that when i tried to execute it it gave me an error the "let: not found". why is that? how can i perform an arithmetic function in the solaris shell script? thanks :) (2 Replies)
Discussion started by: inquirer
2 Replies
Login or Register to Ask a Question