Skip to content

Instantly share code, notes, and snippets.

@mage2k
Created May 9, 2014 23:42
Show Gist options
  • Save mage2k/f9496ec2481544c373a5 to your computer and use it in GitHub Desktop.
Save mage2k/f9496ec2481544c373a5 to your computer and use it in GitHub Desktop.
ssh_agent.sh
#!/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