Created
July 18, 2012 15:06
-
-
Save anonymous/3136741 to your computer and use it in GitHub Desktop.
Sort out your SSH Agent sockets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function agentstatus { | |
echo -n "Agent status: "; | |
if ssh-add -l &>/dev/null; then | |
echo "WORKING" | |
return 0 | |
else | |
echo "BROKEN"; | |
return 1 | |
fi | |
} | |
function lsagent { | |
for sock in /tmp/ssh-*/agent.*; do | |
echo "socket: $sock " | |
if SSH_AUTH_SOCK=$sock ssh-add -l &>/dev/null; then | |
nidents=$(SSH_AUTH_SOCK=$sock ssh-add -l 2>/dev/null | grep -v ident | wc -l) | |
echo -e "\tstatus: WORKING" | |
echo -e "\tidentities: "$nidents"\n" | |
else | |
echo -e "\tstatus: BROKEN\n" | |
fi | |
done | |
} | |
function findagent { | |
if agentstatus; then | |
return 0 | |
fi | |
export res="" | |
for sock in /tmp/ssh-*/agent.*; do | |
echo "Trying agent sock: $sock" | |
export SSH_AUTH_SOCK=$sock | |
res=$sock | |
if ssh-add -l &>/dev/null; then | |
agentstatus | |
return 0 | |
fi | |
done | |
agentstatus | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment