shell, signals and trap question

D. Hugh Redelmeier hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Thu Nov 1 20:29:40 UTC 2007


| From: Neil Watson <tlug-neil-8agRmHhQ+n2CxnSzwYWP7Q at public.gmane.org>
| 
| # Load private key into ssh-agent but, only for 5 minutes
| eval "$(ssh-agent -t 300)" 2>1 1>/dev/null

I'm not sure why you do it this way.  Why not:
	eval `ssh-agent -t 300` >/dev/null 2>&1
What is the redirection for?

| # Add private keys to ssh-agent
| ssh-add
| # Kill ssh-agent on any exit
| trap "eval \"$(ssh-agent -k)\" 2>1 1>/dev/null; exit" INT EXIT

When do you think that ssh-agent will be invoked?

It will be invoked when the shell first sees this line.  That's not
what you want.

You probably don't want to use $(...).

How about something like (UNTESTED):
	trap "ssh-agent -k >/dev/null 2>&1 ; exit" INT EXIT
Notice too that your redirection was a bit off.

| My test case is 'sshdo uptime'. Since I added the trap line I am prompted for
| the ssh key passphrase for each iteration of the loop. This suggests to me
| that
| the trap line is killing ssh-agent after each ssh session is finished. Why?

No, it was executing before any ssh session started.
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list