Re: running ssh/remote cmd in the background

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

 



On 02/28/2017 09:51 AM, bruce wrote:
> On Mon, Feb 27, 2017 at 11:44 PM, bruce <badouglas@xxxxxxxxx> wrote:
>> On Mon, Feb 27, 2017 at 2:56 PM, Rick Stevens <ricks@xxxxxxxxxxxxxx> wrote:
>>> On 02/27/2017 11:35 AM, Jon LaBadie wrote:
>>>> On Mon, Feb 27, 2017 at 09:41:11AM -0800, Rick Stevens wrote:
>>>>> On 02/26/2017 12:34 PM, bruce wrote:
>>>>>> Hey Jon...
>>>>>>
>>>>>> You are absolutely correct.. if the parent ssh terminates.. the remote
>>>> ...
>>>>>
>>>>> Jon, we try not to top-post here. Just a nudge.
>>>>
>>>> I didn't Rick, you attributed the above incorrectly.
>>>>
>>>>>
>>>>> 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 &"
>>>>
>>>> I replied to the original post and the screen command was never mentioned.
>>>
>>> OOPS! My mistake. I should have poked Bruce. Sorry, Jon.
>>
>> hey... no poking in here!!!
>>
> 
> 
> More clarification....
> 
> The following works...
>   ssh -t crawl_user@1.2.3.4 cp /foot/start.php /ctmp/.
> 
> Howvever, i've been putzing with a way to have the local ssh run in
> the background, with no success...
> 
>   ssh -t crawl_user@1.2.3.4 "cp /foot/start.php /ctmp/. " &
> 
> Seems to place the ssh in the background (ps -aux) shows it running,
> but it never dies..
> 
> I've tried different approaches > \dev\null & etc.. with little luck...
> 
> Here's why Im looking to do this:
> 
> My use case/test has a bunch of digital ocean droplets, and the
> process has a number of things that ned to be done to each droplet on
> initialization (I know, whynot create a base instance with what's
> needed, and clone that one!)
> 
> So the current process does a simple loop through the init process,
> doing the remote/ssh into the target instances... This process works,
> but is time consuming. So I've wondered how one could run a local ssh
> in the background, which would/should allow the process to run
> faster...
> 
> loop
>   (ssh user@ip1 remote_process_1) & so the entire local ssh process
> runs as a background
>   (ssh user@ip1 remote_process_2) & so the entire local ssh process
> runs as a background
>   (ssh user@ip1 remote_process_3) & so the entire local ssh process
> runs as a background

First, create a script to run the commands on the remote machine:

	$ cat /usr/local/bin/bkgndstuff.sh
	#!/bin/bash
	ssh user@ip1 "remote_process_1"
	ssh user@ip1 "remote_process_2"
	ssh user@ip1 "remote_process_3"
	...
	ssh user@ip1 "remote_process_n"

	$ chmod 755 /usr/local/bin/bkgndstuff.sh

Then to run it, use screen in detached mode:

	$ screen -d -m -S bkgndstuff /usr/local/bin/bkgndstuff.sh

That will spawn a detached screen session called "bkgndstuff.<PID>"
(where <PID> is the process ID of the screen session itself) which will
run all the commands in /usr/local/bin/bkgndstuff.sh. This is a very
common thing to do in initscripts when you simply want to start a
process at boot that may take a long time to complete.

You can attach to the session by doing:

	$ screen -r bkgndstuff.<PID>

and detach by "CTRL-A, d" while attached.
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer, AllDigital    ricks@xxxxxxxxxxxxxx -
- AIM/Skype: therps2        ICQ: 226437340           Yahoo: origrps2 -
-                                                                    -
-    I don't suffer from insanity...I enjoy every minute of it!      -
----------------------------------------------------------------------
_______________________________________________
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