In the process of developing a method of automatically build the numerous Jekyll based sites I am now running I came across a couple of problems to do with deploying with git, through shell scripts launched by crontab.

Architecturally the sites receive content from shared folders which are symbolically linked in to the Jekyll site folders. A shell script script that is launched by cron runs Jekyll and then use git to version and push the site onto the web server.

Firstly the users own crontab, editable as crontab -e, runs with a different executable path so the user path must be explicitly set within the shell script being used.

export PATH=""

Once the path was set correctly the next issue I faced was the failure of git push commands with this error message.

ssh_exchange_identification: read: Connection reset by peer fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

I gather this is again caused by cron, as cron is unable to access or use the users ssh keys even if they do not require pass phrases. However on Ubuntu 14.04 LTS this can be resolved by prefixing the git command with the home directory path.

HOME=/home/bob git push origin master;

This makes the complete script,

export PATH="/usr/local/sbin:/usr/local/bin"

cd -complete path to folder-

if /usr/local/bin/jekyll build; then
        git add .;
        git commit -m "auto build";
        HOME=/home/bob git push origin master;
else
        echo "build error"
fi

This script can then be launched from cron as required to cd into the build directory, run Jekyll to build the site and then push the site using git.

This works on Ubuntu 14.04 LTS as of today.