Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Backgrounding part of 'ssh-agent $cmd'



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



Messages sorted by: Reverse Date, Date, Thread, Author