Detect existing socket, or not
This commit is contained in:
parent
c99674cae7
commit
da807b773f
14
ssh-agent.sh
14
ssh-agent.sh
|
@ -1,3 +1,17 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ -e $HOME/.spool/ssh-agent.sock ]; then
|
||||||
|
PID=$(tail -n 1 $HOME/.spool/ssh-agent.env | sed 's/echo Agent pid \([0-9]*\);/\1/')
|
||||||
|
if [ -z $PID ]; then
|
||||||
|
pkill ssh-agent
|
||||||
|
rm $HOME/.spool/ssh-agent.*
|
||||||
|
else
|
||||||
|
CMD=$(ps -p $PID -o comm | tail -n 1)
|
||||||
|
if [ ! -z $CMD ] && [ $CMD == 'ssh-agent' ]; then
|
||||||
|
echo "Valid agent already found at $HOME/.spool/ssh-agent.sock with PID $PID"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
eval $(ssh-agent -a $HOME/.spool/ssh-agent.sock | tee $HOME/.spool/ssh-agent.env) >/dev/null
|
eval $(ssh-agent -a $HOME/.spool/ssh-agent.sock | tee $HOME/.spool/ssh-agent.env) >/dev/null
|
||||||
|
|
Loading…
Reference in New Issue