You are not logged in.

#1 2016-04-29 10:57:22

Mr Green
Administrator
Registered: 2010-11-07
Posts: 6,920

run a script via ssh

Does anyone know a simple way to run a script via ssh? I need script to run even after I close ssh session.

Currently trying

ssh -t <user>@<address> "./script"

Comments, suggestions please feel free to contact me mrgreen(at)archbang(dot)org

Offline

#2 2016-04-29 14:14:54

oliver
Administrator
Registered: 2010-11-04
Posts: 2,209

Re: run a script via ssh

that will run ./script if ./script is on the remote server.  I guess if you want to leave it running something like this would work

ssh user@remote "nohup ./script" &

If ./script is local you'll need something like:

ssh user@remote 'bash -s' < ./script &

All thoroughly untested of course

Depending on the situation you might find something like tmux a better fit

ssh to remote... run tmux... detach session... exit.  The script will keep running and you can re-attach at a later date (assuming the remote box doesn't reboot)

Offline

#3 2016-04-30 00:46:05

Mr Green
Administrator
Registered: 2010-11-07
Posts: 6,920

Re: run a script via ssh

Script is on my pi (wifi) can vnc quite easily now but for ease I am going into pi then running script (adding &). Seems to work ok but might try your first method (quicker).

Have notice quite a bit of lag, so added a swap file though it made no real difference so guessing its local wifi.

Thanks


Comments, suggestions please feel free to contact me mrgreen(at)archbang(dot)org

Offline

Board footer

Powered by FluxBB