Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试运行命令,但如果命令在一段时间内没有成功(例如 30 秒),请取消命令并失败。该脚本相当简单,我只是暂停 ntpd,然后强制时间同步并启动。但是,如果存在无效的 ntp 服务器,则会挂起。
systemctl stop ntpd ntpd -gq systemctl start ntpd
我的想法是,我尝试在后台运行它,每 10 秒检查一次命令是否仍在尝试运行。并说在 3 次检查后我是否看到“ntpd -gq”我终止进程并返回失败。这是正确的方法还是有任何内置的时间处理?
外壳没有这种时间处理。
在后台运行该过程并按照您的建议定期检查它是处理此问题的最佳方法。