My Adventure of adding a GIT pull cron job on Mac OS Sierra
I had requirement to periodically check for updates on in a git repository so that a tool that I developed had the most up to date templates so the configuration would generated correctly.
Note: Scroll to the bottom for the answer.
First, I attempted to just add the cron job.
I added this code.
*/1 * * * * cd /Users/dazfre/PycharmProjects/Django-networktool/mysite/forms/scripts/templates && /usr/local/bin/git -q pull origin master
- save and exit
When the job ran, I got this message.
/bin/sh: cd /Users/dazfre/PycharmProjects/Django-networktool/mysite/forms/scripts/templates && /usr/local/bin/git -q pull origin master: No such file or directory
This is when I found out that the
-q for git was causing the directory issue. I removed it, added it with out it and got this error message.
“`Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.“`
OK, so I found out that cron job is a very dumbed down shell and doesn’t have access to my SSH KEY and doesn’t even know where it is. Also, it doesn’t know where the SSH AGENT is.
Since, unfortunately there is no
-i option for git to specify what SSH key you want to use. There are some scripts that you can make, but I didn’t want to make something I didn’t understand, so I did this.
Second, I attempted to tell cron job to setup a SSH agent per job call with a shell script.
I added this code.
- create a script
add the guts
ssh-agent bash -c 'ssh-add /Users/dazfre/.ssh/id_rsa && git pull'
- Exit and save
ctrl + x
Make file executable
chmod a+x gitpull.sh
*/1 * * * * /Users/dazfre/gitpull.sh
save and exit
Will it work? Nope.
This error message is now popping up.
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
What’s an X Crun?
Since, I am using a Mac and updated to Sierra and it want’s you to accept a user agreement. I’ve read mixed results on the —reset option.
I ran this command.