1. use ps h ... instead ps ... | tail -n1 .
2. redirect error msg. from ps to /dev/null (this happen
in case when $SSH_AGENT_PID shell variable is empty).
and most important:
3. check whether existing ssh-agent pid belongs to user
who login.
Changed files:
ssh-agent.sh -> 1.5
SSH_AGENT_DATA="${HOME}/.ssh/SSH-AGENT-DATA"
if [ -s "$SSH_AGENT_DATA" ] ; then
. "$SSH_AGENT_DATA" > /dev/null
- if [ "$(ps -p "$SSH_AGENT_PID" | tail -n1 | awk '{print $4}')" != "ssh-agent" ] ; then
+ if [ "$(ps uhp "$SSH_AGENT_PID" 2>/dev/null | awk '$1 ~ ENVIRON["USER"] {print $11}')" != "ssh-agent" ] ; then
ssh-agent $ssh_agent_flags > "$SSH_AGENT_DATA"
. "$SSH_AGENT_DATA" > /dev/null
fi