Sleep until a specific time/date

前端 未结 18 2093
栀梦
栀梦 2020-11-28 21:13

I want my bash script to sleep until a specific time. So, I want a command like \"sleep\" which takes no interval but an end time and sleeps until then.

The \"at\"-d

18条回答
  •  渐次进展
    2020-11-28 21:21

     function sleepuntil() {
      local target_time="$1"
      today=$(date +"%m/%d/%Y")
      current_epoch=$(date +%s)
      target_epoch=$(date -d "$today $target_time" +%s)
      sleep_seconds=$(( $target_epoch - $current_epoch ))
    
      sleep $sleep_seconds
    }
    
    target_time="11:59"; sleepuntil $target_time
    

提交回复
热议问题