I have a cron job setup to run a bash script to push to Git every night.
The cron job was setup as root, and I have set my git credentials via: git config credential.helper store
as per: Git push: username, password, how to avoid? (second answer)
The code for the bash script is pretty simple
#!/bin/bash
# Nightly push to Bitbucket
# Set some variables
DAY=$(date +%F);
# Make sure we run as root
if [ "$(whoami)" != "root" ]; then
echo "Only root can do this.";
exit 1;
else
# Make sure we are in the right directory
cd /hosting;
# Now add any changes
git add .;
# Now commit
git commit -m "$DAY Nightly";
git push all;
fi;
And runs without a hiccup so long as I log into the server and run it as root.
However, it does not run at the specified time.
Crontab -e is set with: 30 3 * * * back-to-git >/dev/null 2>&1
What can I do to get it to work?