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

Reply

Join Date: Oct 2008
Posts: 1
Reputation: packet is an unknown quantity at this point 
Solved Threads: 0
packet packet is offline Offline
Newbie Poster

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

 
0
  #1
Oct 18th, 2008
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 ....!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 399
Reputation: chris5126 is an unknown quantity at this point 
Solved Threads: 14
chris5126 chris5126 is offline Offline
Posting Whiz

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

 
0
  #2
Oct 27th, 2008
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!
If my post helped add to my rep!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 58
Reputation: omrsafetyo is an unknown quantity at this point 
Solved Threads: 9
omrsafetyo omrsafetyo is offline Offline
Junior Poster in Training

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

 
0
  #3
Nov 6th, 2008
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!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 61
Reputation: Gromit is an unknown quantity at this point 
Solved Threads: 7
Gromit's Avatar
Gromit Gromit is offline Offline
Junior Poster in Training

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

 
0
  #4
Nov 7th, 2008
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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC