【问题标题】:Linux - Do a command repeatedly for a certain length of timeLinux - 在一定时间内重复执行命令
【发布时间】:2017-02-28 05:32:00
【问题描述】:

我知道命令 watch -n 的作用。我想做类似以下的事情:

watch -n 5 "ls" //Do this for 30 minutes, then stop.

基本上我想每 5 秒重复一次命令,然后在 30 分钟后停止。我错过了停止 30 分钟的部分。我应该使用什么命令来实现这一点?

谢谢。

【问题讨论】:

    标签: linux bash shell ubuntu centos


    【解决方案1】:

    使用超时:

    timeout 1800 watch -n 5 "ls" 
    

    【讨论】:

      【解决方案2】:

      您可以使用 timeout 命令,它是 coreutils 的一部分,类似于:

       timeout 30m watch -n 5 "ls"
      

      【讨论】:

      • 请注意,timeout 有多个版本。如果您没有最新的 GNU Coreutils,语法和选项可能会有所不同。
      猜你喜欢
      • 1970-01-01
      • 2018-07-16
      • 2013-04-12
      • 2014-04-22
      • 2021-03-02
      • 2016-12-03
      • 2020-10-10
      • 2013-05-27
      • 2021-08-19
      相关资源
      最近更新 更多