Re: running ssh/remote cmd in the background

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/26/2017 12:34 PM, bruce wrote:
> Hey Jon...
> 
> You are absolutely correct.. if the parent ssh terminates.. the remote
> process would "die".. In my use case, the remote process being fired
> off is actually being run under a remote "Screen" session, so it had
> better survive the ssh terminating!! (In testing, this has worked, so
> I have no reason to think the background process would be any
> different!

Jon, we try not to top-post here. Just a nudge.

If you are using ssh to spawn a remote screen session that runs a
command in the background it should work just fine, e.g.:

	ssh user@remote "screen command-to-run args &"

ssh should log in and start the screen command with the given command
and args in the background, although there's really no need to
background if you use screen. Just run screen with the detached options:

	ssh user@remote "screen -d -m -S session-name command args"

that launches "command" in a detached screen session on the remote
machine and gives the session the name "session-name". This can be
attached to by logging into the remote machine and doing "screen -r"
(if that's the only screen session running" or
"screen -r session-name.pid" (if there are multiple screen sessions).

I use this method all the time. You might also look at pdsh/dshbak if
you're going to poke a bunch of machines at once (sorta like
clusterssh, but not interactive).

> On Sun, Feb 26, 2017 at 2:17 PM, Jon LaBadie <jonfu@xxxxxxxxxx> wrote:
>> On Sun, Feb 26, 2017 at 06:40:50PM +0100, Joachim Backes wrote:
>>> On 02/26/17 18:08, bruce wrote:
>>>> Morn guys...
>>>>
>>>> The following works as a test ssh to fire off a remote cmd. However it
>>>> waits for the cmd to complete befor returning. I'm looking to run th
>>>> cmd as a background on the local/calling instance. Ultimaely, I'll be
>>>> testing this from py/php scripts.
>>>>
>>>> ssh -t user1@67.205.151.05 'cat /cloud/hash2.dat | wc -l'
>>>>
>>>> -would the following work?
>>>>
>>>> ssh -t user1@67.205.151.05 'cat /cloud/hash2.dat | wc -l' &
>>>
>>> It runs the (complete) local ssh cmd (including it's parameters) locally in
>>> background. If you want to run the remote cmd in background
>>> (cat /cloud/hash2.dat | wc -l) you must add the "&" before the closing "'"
>>> and not after.
>>>
>>> But this means your ssh command likely may exit before the remote cmd
>>> finishes. Is this reasonable?
>>>
>>> Kind regards
>>>
>>> Joachim Backes
>>
>> Two other considerations:
>>
>> Where is the output from the pipeline sink (wc -l in this case)
>> going to go?  Without the ssh connection, it will go to stdout,
>> either closed or set to /dev/null.
>>
>> When the ssh connection terminates, I suspect its children
>> processes on the remote to receive the "Hang UP" (your parent
>> has died) signal and will likely commit suicide.
>>
>> Jon
>> --
>> Jon H. LaBadie                  jonfu@xxxxxxxxxx
>> _______________________________________________
>> users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
>> To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
> _______________________________________________
> users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
> 


-- 
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer, AllDigital    ricks@xxxxxxxxxxxxxx -
- AIM/Skype: therps2        ICQ: 226437340           Yahoo: origrps2 -
-                                                                    -
-           What is a "free" gift?  Aren't all gifts free?           -
----------------------------------------------------------------------
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux