Git, Shell and Crontab

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;
        echo "build error"

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.

Moving Computers Checklist and Procedure

So after much though I eventually choose a new laptop. This means it is time to move between computers you might find my procedure and ch...… Continue reading

Should Corbyn Go

Published on June 12, 2017

Post 2017 General Election Now What

Published on June 09, 2017