I hope one of you bash, sed, awk experts out there can help me out. I have this string:
00:00:00:00:00:00%~%System1%~%s0:00-21:40%~%m3:10-17:10%~%t11:20-20:30%~%w05:10-9:30%~%t00:00-21:30%~%f12:00-0:00%~%s6:00-18:00
It is fields separated by “%~%”. The first two fields can be ignored. The remaining fields have day time ranges. This should clarify the format:
00:00:00:00:00:00 <--Mac
System1 <--Name
s00:00-21:40 <--Sunday 12 AM through 9:40 PM
m03:10-17:10 <--Monday 3:10 AM through 5:10 PM
t11:20-20:30 <--Tuesday 11:20 AM through 8:30 PM
w05:10-9:30 <--Wednesday 5:10 AM through 9:30 AM
t00:00-21:30 <--Thursday 12 AM through 9:30 PM
f12:00-0:00 <--Friday 12 PM through 12:00 AM
s06:00-18:00 <--Saturday 6 AM through 6:00 PM
Now the trick…I need to determine if the current system datetime is within the ranges. 🙁
So, if date returns this:
Wed Sep 19 14:26:05 UTC 2012
Then it doesn’t fall within the range specified for Wednesday. I basically need an if statement. I need to execute one script if it is within the range and a different script if it is not. How would I do that with bash, awk, and/or sed?
Thanks for any help you can offer!
I started going down this path:
arr=$(echo $line | tr "%~% " "\n")
for x in $arr
do
#Now what? Some kind of switch/case?
done
I believe that the following script does what you want: