Hello,
I would like to run a process on a remote machine (login through ssh and then su) which will remian running even when I close the connection.
I am not sure that a standard background process (using &) is not going to kill the process when I logout.
Thank.
=========================================================================== Patrick DUPRÉ | | email: pdupre@gmx.com Laboratoire de Physico-Chimie de l'Atmosphère | | Université du Littoral-Côte d'Opale | | ===========================================================================
On 12/21/18 6:36 AM, Patrick Dupre wrote:
I would like to run a process on a remote machine (login through ssh and then su) which will remian running even when I close the connection.
I am not sure that a standard background process (using &) is not going to kill the process when I logout.
Yes, using & isn't going to work. One way would be doing this....
echo "the command you want" | batch
On 12/20/18 2:36 PM, Patrick Dupre wrote:
Hello,
I would like to run a process on a remote machine (login through ssh and then su) which will remian running even when I close the connection.
I am not sure that a standard background process (using &) is not going to kill the process when I logout.
Make sure you have the screen RPM installed on the remote machine, then you can run the command in a screen session:
remote-machine> screen -d -m -S SomeIdentifier <command> <args>
Or from ssh on your local machine:
ssh user@remote-host "screen -d -m -S SomeIdentifier <command> <args>"
In the screen command, the "-d -m" means "run the command in a detached session". The "-S SomeIdentifier" just gives the session an identifiable name. For example, if I use
-S TestScreen
I'd get something like:
remote-machine> screen -ls There is a screen on: 7391.TestScreen (Detached) (other stuff)
Otherwise you'd get something like:
7434.pts-11.prophead (Detached) (other stuff)
To attach to the detached session, use "screen -r <sessionID>", in the example case:
remote-machine> screen -r 7391.TestScreen
Once you're attached to it, you can either "CTRL-C" to end the session or simply detach again by hitting "CTRL-A" followed by the "D" key. See "man screen" for details.
Note that if you put a space in the session identifier, you MUST enclose it in quotes so the shell doesn't try to interpret it. ---------------------------------------------------------------------- - Rick Stevens, Systems Engineer, AllDigital ricks@alldigital.com - - AIM/Skype: therps2 ICQ: 226437340 Yahoo: origrps2 - - - - Microsoft Windows: Proof that P.T. Barnum was right - ----------------------------------------------------------------------
On Thu, 20 Dec 2018 23:10:47 +0000 Rick Stevens ricks@alldigital.com wrote:
I am not sure that a standard background process (using &) is not going to
kill the process when I logout.
Make sure you have the screen RPM installed on the remote machine, then you can run the command in a screen session:
remote-machine> screen -d -m -S SomeIdentifier <command>
<args>
yes I use screen this way routinely, works fine.
d
Or if you want something lighter weight, you could use the bg-dammit program from my web page:
https://tomhorsley.com/game/Mjolnir.html
It is similar to nohup, but it really really backgrounds things.
On 20Dec2018 15:16, Dave Stevens geek@uniserve.com wrote:
On Thu, 20 Dec 2018 23:10:47 +0000 Rick Stevens ricks@alldigital.com wrote:
I am not sure that a standard background process (using &) is not going to
kill the process when I logout.
Make sure you have the screen RPM installed on the remote machine, then you can run the command in a screen session:
remote-machine> screen -d -m -S SomeIdentifier <command>
<args>
yes I use screen this way routinely, works fine.
I use tmux instead of screen, but yes this is my usual practice too. Give your session a meaningful name, it will be handy later.
The recipes recited kick off a command already "detached" (running in screen, but don't leave you connected). I generally open a named session and start the command interactively. That lets me see it get under way and lets me handle minor mistakes. And its in a shell ready to be interrupted, suspended, restarted, whatever.
I do this so routinely that I've got an alias "@" which runs an elaborate shell function, so I go:
@ remotehost:SESSION_NAME
whih sshes into remotehost in a tmux session named "SESSION_NAME". Once it's good, just detach.
And it records the host and session in the local shell. So if I've just got a shell lurking on my never-shut-down laptop, I kick that off. And later, in that same shell, just type "@" to reconnect to the same session.
Cheers, Cameron Simpson cs@cskk.id.au
Patrick Dupre wrote:
Hello,
I would like to run a process on a remote machine (login through ssh and then su) which will remian running even when I close the connection.
I am not sure that a standard background process (using &) is not going to kill the process when I logout.
Thank.
Try daemonize if that suits your needs.
Hi.
On Thu, 20 Dec 2018 23:36:08 +0100 "Patrick Dupre" wrote:
I would like to run a process on a remote machine (login through ssh and then su) which will remian running even when I close the connection.
You can use systemd-run: your process will be run as a systemd service.
In addition to be protected from logout, you will thus be able to control this process with systemctl and to see its output with journalctl.