#!/bin/bash

if [ "$#" -ne 1 ]; then
		echo 'usage: ssh-grab-agent.sh PID'
		exit 1
fi

PID=$1

export SSH_AUTH_SOCK=$(/bin/ls /tmp/ssh-*/agent.$PID 2>/dev/null)
if [ -z "$SSH_AUTH_SOCK" ] ; then
    let "PID2 = PID-1"
    export SSH_AUTH_SOCK=$(/bin/ls /tmp/ssh-*/agent.$PID2)
fi
echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK"
echo "export SSH_AGENT_PID=$PID"

exit 0
