Skip to content

Instantly share code, notes, and snippets.

@farrokhi
Created January 19, 2020 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farrokhi/c5fb999918ea79d8912e7967e53702e8 to your computer and use it in GitHub Desktop.
Save farrokhi/c5fb999918ea79d8912e7967e53702e8 to your computer and use it in GitHub Desktop.
Ensure ssh-agent is running and you have proper env variables set (re-use if possible)
AGENT_SCRIPT=${HOME}/load-agent.sh
while true; do
[ -r ${AGENT_SCRIPT} ] && source ${AGENT_SCRIPT}
if [ -n "$SSH_AGENT_PID" ]; then
# ensure the variable actually reflects a running ssh-agent process
ps -p $SSH_AGENT_PID | grep -q ssh-agent$ && break
fi
# SSH_AGENT_PID is either not set or has stale PID
echo "Running ssh-agent"
ssh-agent > ${AGENT_SCRIPT}
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment