Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe that the following script does what you want:</p> <pre><code>#!/bin/bash # Function which returns true (0) on a time being in a range, false (1) otherwise # call as: time_between $time $range # where $range is of the format 'START-END' time_between() { current_time=$1 range=$2 start_time=$(echo $range | cut -d'-' -f1); end_time=$(echo $range | cut -d'-' -f2); # Correct if ends at midnight if [[ $end_time -eq 0 ]]; then let end_time=2400 fi # Test is time is within the window if [[ $current_time -ge $start_time &amp;&amp; $current_time -le $end_time ]] then return 0; fi # Else the time is outside the window return 1; } # Set the line variable - you may want this to come from somewhere else in the end line="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" i=0 # Extract the day and time (hours and minutes) from the `date` command DATE=$(date) day=$(echo $DATE | cut -d' ' -f1) time=$(echo $DATE | cut -d' ' -f4 | cut -d: -f1-2 | tr -d ':') # Marker for which token in the line to start the days from: token 3 is monday dayno=2 # Set the dayno so we're pointing at the current day case $day in Mon) let dayno+=1 ;; Tue) let dayno+=2 ;; Wed) let dayno+=3 ;; Thu) let dayno+=4 ;; Fri) let dayno+=5 ;; Sat) let dayno+=6 ;; Sun) let dayno+=7 ;; esac arr=$(echo $line | tr '%~%' '\n' | tr -d '[a-z]:') for x in $arr do let i+=1; #Now what? Some kind of switch/case? if [[ $i -eq $dayno ]]; then if time_between $time $x; then echo "Were within the window!" else echo "We missed the window!" fi fi done </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload