ssh give command and then disconnect/quit

ericovk

Verified User
Joined
Apr 17, 2012
Messages
229
Location
Rotterdam, Netherlands
I was wondering if it's possible to login with ssh, then give a command (like scan for virusses or copy from server to server) and then quit ssh/terminal?

It would be really nice if this is possible so I don't have to wait minutes/hours for a long task to complete and keep the connection alive until the task has completed.
 
Why not? But in that case I would make a little script, something like this
Code:
#!/bin/bash
command &
exit
The & code puts the command in the background and then you can logoff without stopping the command.
 
Thanks Richard, this is extremely nice! :cool:

If you login again, can you view the current task again (like if you scan or copy in verbose mode)? Or do I have to start $top for that?
 
You're welcome.:)

I'm not sure if I understand your other question correctly. You mean if you can view if the task is still running?
You should be able to do that with "ps x" or "ps faux" which shows running processes.
Or do you mean something else?
 
What I actually ment is that you see the processing of each file when you so something in verbose mode. For instance, if you give the command:
Code:
scp /home/admin/admin_backups/* [email protected]:~

Terminal shows the processing of each file. Is it possible to put scp in the background with
Code:
scp /home/admin/admin_backups/* [email protected]:~ & exit

Log out and then log back in and see what the progress of scp is?
 
Sorry I don't now. I normally never use ssh like that. There is a chance it's possible, maybe when you run it with "screen". But as said... I'm not sure, maybe somebody else knows.
 
Back
Top