如何每秒运行一个特定的脚本?

Pra*_*har 4 shell scripting shell-script watch

我曾尝试使用 crontab,但仅限于几分钟。还有其他选择吗?

我也尝试过类似的事情:

watch -n 1 sh /path-to-script/try.sh
Run Code Online (Sandbox Code Playgroud)

但是每当我关闭终端时它就会停止。我想要一些在后台持续工作的东西。

Nar*_*asK 6

使用带有while循环和的脚本nohup

the_script.sh :

while :; do
  /path-to-script/try.sh
  sleep 1
done
Run Code Online (Sandbox Code Playgroud)

运行the_script.sh不受挂断影响:

nohup /path/to/the_script.sh > /dev/null
Run Code Online (Sandbox Code Playgroud)

更换/dev/null如果你关心什么是在一些文件路径stdout

  • 我做了同样的事情。它运行完美...感谢您的帮助;) (2认同)