Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Extract SSH_AUTH_SOCK from SSHKeychain (OS X)

by adrianh (Chancellor)
on Feb 06, 2007 at 13:49 UTC ( #598538=snippet: print w/ replies, xml ) Need Help??

Description:

I use the handy app SSHKeychain on my OS X box, which handles my SSH agent for me in various useful ways. The only problem is that the environment doesn't get set up properly for things like cron (since SSHKeychain stores it's socket info in a .plist).

This little snipped enables me to do things like:

with-sshkeychain svk sync -a 2>&1 | mail -s svk-sync-all adrianh

in my crontab and still get a connection to the SSHKeychain run ssh-agent. Super.

#! /usr/local/bin/perl

# with-sshkeychain SOME OTHER COMMAND

use Mac::PropertyList;

my $plist =
  Mac::PropertyList::parse_plist_file(
    "$ENV{ HOME }/.MacOSX/environment.plist" )
  or die "cannot parse environment.plist\n";

$ENV{ SSH_AUTH_SOCK } = $plist->value( 'SSH_AUTH_SOCK' )
  or die "no SSH_AUTH_SOCK\n";

exec( @ARGV );
Comment on Extract SSH_AUTH_SOCK from SSHKeychain (OS X)
Download Code
Re: Extract SSH_AUTH_SOCK from SSHKeychain (OS X)
by Fletch (Chancellor) on Feb 06, 2007 at 15:30 UTC

    Of course since SSHKeychain always tends to use /tmp/$UID/SSHKeychain.socket (as long as I've been using it) one could probably safely hard code that in the crontab instead.

      Since the path is an option in the preferences, you can definitely safely hardcode it, as long as it matches what is in the preferences.


      We're not surrounded, we're in a target-rich environment!
Re: Extract SSH_AUTH_SOCK from SSHKeychain (OS X)
by jasonk (Parson) on Feb 08, 2007 at 22:40 UTC

    You could also just go into the SSHKeychain preferences and check the box that says 'Manage (and modify) global environment variables', so that it will set $SSH_AUTH_SOCK for you.


    We're not surrounded, we're in a target-rich environment!
      You could also just go into the SSHKeychain preferences and check the box that says 'Manage (and modify) global environment variables', so that it will set $SSH_AUTH_SOCK for you.

      Erm. No. The whole point is that the way that SSHKeychain manages the environment (via the  .MacOSX/environment.plist in your home directory) doesn't propagate to some things like cron which are independent of your login.

Re: Extract SSH_AUTH_SOCK from SSHKeychain (OS X)
by Anonymous Monk on Sep 27, 2007 at 21:12 UTC
    Thanks for the comments above. The key was to set the SSH_AUTH_SOCK variable at the head of the file. I have no use for the sexy perl code, though, since I will keep this constant. I can now run cron jobs authorized with SSHKeychain using the following crontab:
    SSH_AUTH_SOCK=/tmp/501/SSHKeychain.socket 0 15 * * 1-5 /usr/bin/backup

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://598538]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-12-27 09:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls