如何让unix脚本每15秒运行一次? [英] How to get a unix script to run every 15 seconds?

查看:36
本文介绍了如何让unix脚本每15秒运行一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了一些解决方案,包括 watch 和在后台简单地运行一个循环(和睡眠)脚本,但没有一个是理想的.

I've seen a few solutions, including watch and simply running a looping (and sleeping) script in the background, but nothing has been ideal.

我有一个需要每 15 秒运行一次的脚本,由于 cron 不支持秒,所以我不得不想办法解决其他问题.

I have a script that needs to run every 15 seconds, and since cron won't support seconds, I'm left to figuring out something else.

在 unix 上每 15 秒运行一个脚本的最健壮和最有效的方法是什么?该脚本也需要在重新启动后运行.

What's the most robust and efficient way to run a script every 15 seconds on unix? The script needs to also run after a reboot.

推荐答案

我会使用 cron 每分钟运行一个脚本,并让该脚本运行您的脚本四次,两次运行之间有 15 秒的睡眠时间.

I would use cron to run a script every minute, and make that script run your script four times with a 15-second sleep between runs.

(假设您的脚本可以快速运行 - 如果没有,您可以调整睡眠时间.)

(That assumes your script is quick to run - you could adjust the sleep times if not.)

这样,您可以获得 cron 的所有好处以及 15 秒的运行时间.

That way, you get all the benefits of cron as well as your 15 second run period.

另见下面@bmb的评论.

See also @bmb's comment below.

这篇关于如何让unix脚本每15秒运行一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆