943,546 Members | Top Members by Rank

Ad:
Oct 18th, 2008
0

How to check my conditions....!!!

Expand Post »
Hello All,

I am facing one basic problem please help me out

here is my script

while [ 1 ]
sleep 2

data=16:37

one=15:00
two=17:00


I need to check that is data lies between one and two ( data has to satisfy both one and two )

done

how?

please help ....!!!!!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
packet is offline Offline
1 posts
since Oct 2008
Oct 27th, 2008
0

Re: How to check my conditions....!!!

a simple if statment will work

this isnt the syntax but just a clue!

if data > one && data < two
then
do something
else
do something else
fi

You should note these forums arent for using us to do your homework if you show some effort we will help but we wont do it for u!
Reputation Points: 38
Solved Threads: 15
Posting Pro in Training
chris5126 is offline Offline
412 posts
since Feb 2006
Nov 6th, 2008
0

Re: How to check my conditions....!!!

Another suggestion - since it looks like you are comparing military time, it will be easier to make the comparison if you drop the ":".

You can do this with sed or tr or even cut very easily.
After that, you can do the if comparison. Otherwise you will need to use cut to break each time into two integers for comparison with three logics!
Reputation Points: 13
Solved Threads: 9
Junior Poster in Training
omrsafetyo is offline Offline
58 posts
since Apr 2008
Nov 7th, 2008
0

Re: How to check my conditions....!!!

Okay, I needed something to get my mind off work for a few minutes, so here's a quick script I wrote using both of the suggestions above from chris5126 and omrsafetyo. I didn't translate the date, I used the date command to format the date without colons. Here goes, hope it helps!

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/sh
  2.  
  3. one=143300
  4. two=143400
  5.  
  6. while true; do
  7.  
  8. time="$(date +%H%M%S)"
  9.  
  10. if [ $time -gt $one ] && [ $time -lt $two ]; then
  11. echo "$time We're in the zone\!"
  12.  
  13. elif [ $time -gt $one ] && [ $time -gt $two ]; then
  14. echo "$time The time has passed"
  15.  
  16. elif [ $time -lt $one ] && [ $time -lt $two ]; then
  17. echo "$time It's not time yet..."
  18. fi
  19.  
  20. sleep 10
  21.  
  22. done

And here's the output:

Shell Scripting Syntax (Toggle Plain Text)
  1. $ sh ./timecompare.sh
  2. 143204 It's not time yet...
  3. 143214 It's not time yet...
  4. 143224 It's not time yet...
  5. 143234 It's not time yet...
  6. 143244 It's not time yet...
  7. 143254 It's not time yet...
  8. 143304 We're in the zone\!
  9. 143314 We're in the zone\!
  10. 143324 We're in the zone\!
  11. 143334 We're in the zone\!
  12. 143344 We're in the zone\!
  13. 143354 We're in the zone\!
  14. 143404 The time has passed
  15. 143414 The time has passed

Enjoy!
Reputation Points: 46
Solved Threads: 28
Junior Poster
Gromit is offline Offline
183 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: awk percentage problem
Next Thread in Shell Scripting Forum Timeline: How to generate a temp file until finish selected then replace to another file.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC