以bash测试当前小时?

时间:2018-09-07 23:22:37

标签: bash shell date

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

如何实现?

[
  { 
    _id: 5b64c23eef5b9c5c60fa42a0,
    title: 'Test Post',    
    post: 'Show me the money!',
    postedOn: 2018-08-29T00:00:00.000Z
  },
  { 
    _id: 5afb58408341f161a0c96608,
    title: 'Test Post 2',    
    post: 'Show me the money!',
    postedOn: 2018-08-29T00:00:00.000Z
  } 
]

1 个答案:

答案 0 :(得分:1)

  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