Created
May 30, 2018 06:54
-
-
Save alice1017/324fca024ff3f1661427058fa50db569 to your computer and use it in GitHub Desktop.
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
| #!/bin/bash | |
| # coding: utf-8 | |
| BINPATH="/usr/bin" | |
| SSH_AGENT="${BINPATH}/ssh-agent" | |
| SSH_ADD="${BINPATH}/ssh-add" | |
| FILE="/tmp/ssh-agent.sh" | |
| SSH_ADD_ARGUMENTS=$@ | |
| delete_exists_proc() { | |
| local pid="$(cat $FILE | head -2 | tail -1 | cut -d ";" -f 1 | cut -d "=" -f 2)" | |
| ps aux | grep ssh-agent | grep -v grep | grep -v $pid | awk '{ print $2 }' > /dev/null 2>&1 | |
| } | |
| if [ -e $FILE ];then | |
| delete_exists_proc | |
| source $FILE | |
| $SSH_ADD $SSH_ADD_ARGUMENTS | |
| else | |
| $SSH_AGENT | head -2 | tail -2 > $FILE | |
| $SSH_ADD $SSH_ADD_ARGUMENTS | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment