Re: running ssh/remote cmd in the background
On 02/28/2017 09:51 AM, bruce wrote: > On Mon, Feb 27, 2017 at 11:44 PM, bruce wrote: >> On Mon, Feb 27, 2017 at 2:56 PM, Rick Stevens 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." (where 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. and detach by "CTRL-A, d" while attached. -- - Rick Stevens, Systems Engineer, AllDigitalri...@alldigital.com - - AIM/Skype: therps2ICQ: 226437340 Yahoo: origrps2 - -- -I don't suffer from insanity...I enjoy every minute of it! - -- ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
On Mon, Feb 27, 2017 at 11:44 PM, bruce wrote: > On Mon, Feb 27, 2017 at 2:56 PM, Rick Stevens 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 . . ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
On Mon, Feb 27, 2017 at 2:56 PM, Rick Stevens 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!!! > -- > - Rick Stevens, Systems Engineer, AllDigitalri...@alldigital.com - > - AIM/Skype: therps2ICQ: 226437340 Yahoo: origrps2 - > -- > ___ > users mailing list -- users@lists.fedoraproject.org > To unsubscribe send an email to users-le...@lists.fedoraproject.org ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
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. -- - Rick Stevens, Systems Engineer, AllDigitalri...@alldigital.com - - AIM/Skype: therps2ICQ: 226437340 Yahoo: origrps2 - -- ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
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. Jon -- Jon H. LaBadie jo...@jgcomp.com ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
On Mon, 27 Feb 2017 09:41:11 -0800 Rick Stevens wrote: > If you are using ssh to spawn a remote screen session that runs a > command in the background it should work just fine Unless, of course, your ssh agent is being forwarded from way back on the host system and you need the agent to be active so commands that will be started during the background run will have access to the keys (just one obscure complication that can happen with ssh :-). Probably doesn't happen often, but it can be quite confusing when it does. ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
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 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 jo...@jgcomp.com >> ___ >> users mailing list -- users@lists.fedoraproject.org >> To unsubscribe send an email to users-le...@lists.fedoraproject.org > ___ > users mailing list -- users@lists.fedoraproject.org > To unsubscribe send an email to users-le...@lists.fedoraproject.org > -- -- - Rick Stevens, Systems Engineer, AllDigitalri...@alldigital.com - - AIM/Skype: therps2ICQ: 226437340 Yahoo: origrps2 - -- - What is a "free" gift? Aren't all gifts free? - -- ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
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! Thanks On Sun, Feb 26, 2017 at 2:17 PM, Jon LaBadie 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 jo...@jgcomp.com > ___ > users mailing list -- users@lists.fedoraproject.org > To unsubscribe send an email to users-le...@lists.fedoraproject.org ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
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 jo...@jgcomp.com ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: running ssh/remote cmd in the background
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 Im not sure if the "&" would be applied to the remote or local side for the ssh. And yeah, I know I could run a few tests... but I thought I'd get the opinion of some of you guys as well...!! Thanks ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org -- Fedora release 25 (Twenty Five) Kernel-4.9.12-200.fc25.x86_64 Joachim Backes https://www-user.rhrk.uni-kl.de/~backes/ ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
running ssh/remote cmd in the background
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' & Im not sure if the "&" would be applied to the remote or local side for the ssh. And yeah, I know I could run a few tests... but I thought I'd get the opinion of some of you guys as well...!! Thanks ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org