Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在bash中测试当前时间?_Bash_Shell_Date - Fatal编程技术网

在bash中测试当前时间?

在bash中测试当前时间?,bash,shell,date,Bash,Shell,Date,如何测试当前小时是否等于shell中的给定小时? 小时应为24小时格式 如何实现这一点 While true: do current_hour = ... if current_hour == 21: python aaa.py done 是否可以使用at调度python程序?如果您想在21:00运行一次,请输入crontab。或者您的意思是,正如所写的,您希望在21:00-21:59之间尽可能多地运行Python? while true;

如何测试当前小时是否等于shell中的给定小时?
小时应为24小时格式

如何实现这一点

While true:
    do
    current_hour = ...
    if current_hour == 21:
        python aaa.py
    done

是否可以使用
at
调度python程序?如果您想在21:00运行一次,请输入
crontab
。或者您的意思是,正如所写的,您希望在21:00-21:59之间尽可能多地运行Python?
  while true; do
      hour=$(date +%H)
      if [ $hour == 21 ] ; then 
          python aaa.py
      fi
      # now sleep until next hour
      sleep $(((60 - $(date +%M))*60))
  done