Visit Our UNIX and Linux User Community


If then logic with TIME


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If then logic with TIME
# 1  
Old 08-29-2013
If then logic with TIME

Hi all,

Can anyone suggest how to formulate the if/then when TIME equals a certain time, in this case 23:55:00


Code:
export TIME=`date +%T`

function tnsrec {
if $TIME = 23:55:00; then
otherfunction
else exit
fi
}


Thanks in advance.

jd
# 2  
Old 08-29-2013
Code:
export TIME=`date +%T`

function tnsrec {
if [ $TIME = "23:55:00" ]
then
    #otherfunction
else
    exit
fi
}

# 3  
Old 08-29-2013
Note that if you're off by one second, it won't work...
# 4  
Old 08-29-2013
Hmm yes, good point.

How do I introduce a 'BETWEEN' condition?
ie something like
Code:
export TIME=`date +%T`  
function tnsrec 
{ if [ $TIME >= "23:55:00" OR $TIME < "23:55:59"] 
then     
#otherfunction 
else  exit 
fi 
}

Any ideas?
# 5  
Old 08-29-2013
You could try stripping the colons and using it as an integer with -eq -gt -ge etc.
# 6  
Old 08-29-2013
Code:
export TIME=$(date +"%H%M")
function tnsrec
{ if [ $TIME -eq 2355 ]
    then   #otherfunction  
    else   exit
  fi
}

# 7  
Old 08-29-2013
Thanks for your reply.

I think I need to be able to check if TIME is between two DATEs.

that was I dont have to be sp specific about the TIME which could be a problem if you are out by 1 second or so.

So I believe I need a command to check a between condition.

Previous Thread | Next Thread
Test Your Knowledge in Computers #185
Difficulty: Medium
Moderating questions and answers at UNIX.com requires superior UNIX shell scripting abilities.
True or False?

1 More Discussions You Might Find Interesting

1. IP Networking

what the logic

i have a text file which contain some text like we|are|one|only i|am|learning|c++ the input from stdout will be input1 we input2 one it should search in the file where this two strings are and then give the output : output1 are output2 only similarly input1 i (2 Replies)
Discussion started by: ramneek
2 Replies

Featured Tech Videos