I have the following bash script to start the ssh-agent, add my keys and do a git pull on a repo. The agent is started, the key is added but the git pull doesn't execute...at least nothing is echo'd to the terminal. The git command works if I type it into the terminal...is there something I need to do within my bash script to make it work?
#!/bin/bash
# if we can't find an agent, start one, and restart the script.
if [ -z "$SSH_AUTH_SOCK" ] ; then
exec ssh-agent bash -c "ssh-add ; $0"
exit
fi
exec ssh-add ~/.ssh/mykey
git --git-dir=/var/www/node/myapp/.git pull origin master
When I add -x to #!/bin/bash this is the terminal output
+ '[' -z '' ']'
+ exec ssh-agent bash -c 'ssh-add ; ./startgit.sh'
+ '[' -z /tmp/ssh-<redacted>/agent.1733 ']'
+ exec ssh-add /home/ec2-user/.ssh/mykey
Identity added: /home/ec2-user/.ssh/mykey (/home/ec2-user/.ssh/mykey)
SSH_AUTH_SOCKis empty? Did you try "debugging" it (#!/bin/bash -xto echo the commands being run)?