Run command `at ` 5 seconds from now

前端 未结 8 1723
甜味超标
甜味超标 2020-12-29 05:03

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\'

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 05:25

    at doesn't use seconds, only minutes/hours/days

    What you can do is precede your script with nohup, which will ensure the script isn't killed when you disconnect your SSH session.

    ssh server 'nohup yourscript.sh &'

    NOTE: Having just played with the above, the SSH connection has to be killed manually.

    Another alternative would be screen

    screen -d -m yourscript.sh

    This will launch a detached screen process that you can reattach to at any time later.

    NOTE: I've tested this with the following script and command and it worked perfectly.

    SSH command

    ssh server.com 'screen -d -m ~/myscript.sh'

    myscript.sh

    #!/bin/sh
    sleep 10
    echo "hello world" > /tmp/hello
    exit;
    

提交回复
热议问题