bash 如何在几秒钟内安排我的服务器定时重启?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22389795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I schedule a timed reboot of my server in seconds?
提问by Dave
I'm using bash shell on Linux …
我在 Linux 上使用 bash shell ...
$ uname -a
Linux sandbox.mydomain.com 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
although it would be nice if I could come up with a solution in any bash supported environment. My question is, in my script I want to scheduled a delayed reboot of my server in 5 seconds. So far, I have the below, but it takes 60 seconds …
尽管如果我能在任何支持 bash 的环境中提出解决方案,那就太好了。我的问题是,在我的脚本中,我想在 5 秒内安排延迟重启我的服务器。到目前为止,我有以下内容,但需要 60 秒……
# Timed reboot of server
sudo shutdown -r 1
# Fail if any of the sub-deployments failed.
if [[ ( $PROC1_STATUS -ne 0 ) ||
( $PROC2_STATUS -ne 0 ) ||
( $PROC3_STATUS -ne 0 ) ]]
then
exit 1;
fi
Does anyone know how I can adjust the above except make the timed reboot in 5 seconds instead of a minute? The solution doesn't have to use "shutdown" but it was the only tool I could find.
有谁知道除了在 5 秒而不是一分钟内进行定时重启之外,我可以如何调整上述内容?该解决方案不必使用“关机”,但它是我能找到的唯一工具。
- Dave
- 戴夫
回答by Basile Starynkevitch
Try
尝试
sleep 5 ; reboot
on your terminal (as root). If you want it in the background, try
在您的终端上(以 root 身份)。如果你想在后台,试试
( sleep 5 ; reboot ) &
See also shutdown(8)
另见关机(8)