Skip to content

Instantly share code, notes, and snippets.

@alice1017
Created May 30, 2018 06:54
Show Gist options
  • Select an option

  • Save alice1017/324fca024ff3f1661427058fa50db569 to your computer and use it in GitHub Desktop.

Select an option

Save alice1017/324fca024ff3f1661427058fa50db569 to your computer and use it in GitHub Desktop.
#!/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