zsh-users
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: Backgrounding part of 'ssh-agent $cmd'
Date: Mon, 21 Jan 2013 05:58:26 +0200	[thread overview]
Message-ID: <20130121035826.GC2968@lp-shahaf.local> (raw)
In-Reply-To: <130118073522.ZM24670@torch.brasslantern.com>

Bart Schaefer wrote on Fri, Jan 18, 2013 at 07:35:22 -0800:
> On Jan 18,  4:13pm, Daniel Shahaf wrote:
> >
> > The part that I find less than ideal so far is that, under load, the GUI
> > ssh-askpass dialog appears after foo_main has started.
> 
> You could do it like this:
> 
>   ( # Subshell so caller's environment won't be changed; could instead
>     # declare locals, but this is immune to changes in ssh-agent
>     eval `ssh-agent`
>     ssh-add ~/.ssh/foo.id_rsa
>     {
>       for h in host1 host2 host3; do 
>         ssh -MNf $h &
>       done
>       wait
>     } always {
>       ssh-agent -k
>     } &
>   )
> 
> Then you don't have to background foo_ssh_preseed, and your preferred
> order of events is retained.

Thanks!  This makes the ssh prompt textual again, while keeping the loop
backgrounded; that's perfect.

To summarise, now I have:

foo_ssh_preseed() {
  if [ -S ~/.ssh/ControlPath/host1 ]
  then
    return
  fi
  zsh -fc '
    # Subshell so caller"s environment won"t be changed; could instead
    # declare locals, but this is immune to changes in ssh-agent
    eval `ssh-agent | tee /dev/stderr`
    ssh-add ~/.ssh/foo.id_rsa
    {
      for h in \
          host1 host2 host3 \
      ; do 
        ssh -MNf $h &
      done
      wait
    } always {
      ssh-agent -k
    } &
  '
}

Which relies on ControlPath,ServerAliveInterval,IdentityFile being set
in ~/.ssh/config.

I also had the subshell use -f --- mainly because I didn't know of
anything else in my configuration would interfere with the always{}
block, but upon review I notice it has the side-effect of making the
enclosing function a valid /bin/sh function.

Thanks again.

Daniel


      reply	other threads:[~2013-01-21  3:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-16  6:59 Daniel Shahaf
2013-01-16 17:35 ` Bart Schaefer
2013-01-18  6:18   ` Daniel Shahaf
2013-01-18  7:26     ` Bart Schaefer
2013-01-18 14:13       ` Daniel Shahaf
2013-01-18 15:35         ` Bart Schaefer
2013-01-21  3:58           ` Daniel Shahaf [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130121035826.GC2968@lp-shahaf.local \
    --to=d.s@daniel.shahaf.name \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).