【问题标题】:Set timeout shell script设置超时 shell 脚本
【发布时间】:2015-12-04 07:45:16
【问题描述】:

我想在我的 shell 脚本中设置超时,这是我的代码:

 /etc/init.d/ntp stop
until ping -nq -c3 8.8.8.8; do
   echo "Waiting for network..."
done
ntpdate -s time.nist.gov
/etc/init.d/ntp start

我想设置超时 30 秒,如果超过 30 秒我想终止该进程并更改为该进程:

hwclock -s

谢谢

【问题讨论】:

  • 为什么是python标签?

标签: bash timeout


【解决方案1】:

在 bash 中,您可以使用 timeout

timeout 30s script.sh
hwclock -s

【讨论】:

  • thaknyou,但我想在我的脚本中超时。你有什么建议吗?
  • @ImamAbdulMahmudi 是什么阻止您在脚本中使用超时?