从现在起5秒后执行命令` [英] Run command `at ` 5 seconds from now
问题描述
作为一个稍微复杂的脚本的一部分,我需要告诉服务器运行模拟.通常,我可以通过执行ssh user@server 'simulation/script'
来实现.但是,这样做会使ssh会话保持活动状态,直到完成'simulation/script'
为止,这对我来说是不希望的.
As part of a slightly complex script, I need to tell a server to run a simulation. Normally, I would achieve this by doing ssh user@server 'simulation/script'
. However, doing so would keep the ssh session alive until 'simulation/script'
is done, which is undesirable to me.
我最近了解了at
命令,它似乎很适合我的问题.
我现在要执行的操作是将ssh插入服务器,并使at
模拟脚本在5秒内运行(关闭ssh连接的时间已足够).因此,一旦ssh连接在5秒钟内关闭,服务器将启动仿真,而无需ssh连接保持活动状态.
I recently learned about the at
command, and it seems to fit into my problem well.
What I want to do now is to ssh into my server, and at
my simulation script to run in 5 seconds (more than enough time for the ssh connection to be closed). Thus, once the ssh connection is closed within 5 seconds, the server will start the simulation without needing the ssh connection to stay alive.
我遇到的麻烦是at
安排工作从现在开始5秒"所需的时间表达.
What I'm having trouble with is the time expression that at
needs in order to schedule a job "5 seconds from now"
我尝试了以下时间表达式,所有这些都会给我带来错误:
I have tried the following time expressions, all of which give me errors:
now + 5 seconds
now + 5 sec
now + 5 s
now + 5seconds
now + 5sec
now + 5 s
now+5sec
now+5seconds
now+5s
如何让我的at
在从现在开始5秒"内运行命令?
How can I get my at
to run my command "5 seconds from now"?
推荐答案
在以下时间没有秒:
man at
说:
日期的
- 规范必须遵循一天中时间的规范.您还可以给像现在这样的时间+计算时间单位, 时间单位可以是分钟,小时,天或周,并且 您可以告诉我们今天加班时间,今天开始工作,明天加班时间,明天开始工作 明天.
- specification of a date must follow the specification of the time of day. You can also give times like now + count time-units, where the time-units can be minutes, hours, days, or weeks and you can tell at to run the job today by suffixing the time with today and to run the job tomorrow by suffixing the time with tomorrow.
因此,我认为可以使用sleep
代替at
.
So instead of at
, you could use a sleep
I think.
请参见man 1 sleep
如果您希望不等待而运行ssh user@server 'simulation/script'
,只需执行:
If you'd like to run ssh user@server 'simulation/script'
without waiting, simply do :
ssh user@server 'simulation/script' &
该命令将在后台运行.
此外,正如Rawkode所说,nohup
将为您提供帮助.
Moreover, as Rawkode said, nohup
will help there.
所以终于:
nohup ssh user@server 'simulation/script' &
使用nohup,您可以退出终端并恢复ssh
进程.
with nohup, you can quit your terminal and have the ssh
process alive.
EDIT
:如果要运行ssh
命令并关闭连接:
EDIT
: if you want to run the ssh
command and close the connection :
ssh user@server 'simulation/script &'
这篇关于从现在起5秒后执行命令`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!