Created
May 9, 2014 23:42
-
-
Save mage2k/f9496ec2481544c373a5 to your computer and use it in GitHub Desktop.
ssh_agent.sh
This file contains 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
#!/bin/sh | |
# | |
# Check that the ssh-agent is running, and if not, kick it off | |
# | |
if [[ -z $SSH_AUTH_SOCK ]]; then | |
SOCKETFILE="${HOME}/.ssh/ssh-agent.socket" | |
else | |
SOCKETFILE=${SSH_AUTH_SOCK} | |
fi | |
/bin/ps -wU ${USER} | /usr/bin/grep "[s]sh-agent" > /dev/null | |
if [[ $? -gt 0 ]]; then | |
/bin/rm -f ${SOCKETFILE} | |
/usr/bin/ssh-agent -a ${SOCKETFILE} > /dev/null | |
/bin/chmod 600 ${SOCKETFILE} | |
/usr/bin/ssh-add | |
fi | |
SSH_AGENT_PID=`ps aux | grep '[s]sh-agent' | awk '{print $2}'` | |
export SSH_AGENT_PID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment