I'm trying to commit/push changes to a remote Git server with the below sample code:
#!/bin/sh
USER='username'
REPO='/home/'${USER}'/Sites/git/bitbucket/kb'
COMMIT_TIMESTAMP=`date +'%Y-%m-%d %H:%M:%S %Z'`
DATELOG=`date +'%Y-%m-%d-%H-%M-%S'`
LOG="/tmp/${DATELOG}.txt"
MKDOCS=`which mkdocs`
GIT=`which git`
NOTIFY=`which notify-send`
# Only proceed if we have a valid repo.
if [ ! -d ${REPO}/.git ]; then
echo "${REPO} is not a valid git repo! Aborting..." >> ${LOG}
exit 0
else
echo "${REPO} is a valid git repo! Proceeding..." >> ${LOG}
fi
cd ${REPO}
${MKDOCS} build --clean >> ${LOG}
${GIT} add --all . >> ${LOG}
${GIT} commit -m "Automated commit on ${COMMIT_TIMESTAMP}" >> ${LOG}
${GIT} push git@bitbucket.org:username/repo.git master >> ${LOG}
# Depends on libnotify
${NOTIFY} 'KB notification' 'Changes were pushed to Bitbucket.' --icon=dialog-information >> ${LOG}
If I invoke the shell script manually (e.g. ./commit.sh
) it works immediately. On the contrary, when triggered via a cron job everything works just fine until the git push
which then never seems to be triggered for some odd reason.
Here's my crontab line:
*/20 * * * * /home/username/Sites/git/repo/commit.sh
And some verbosity for git push
09:53:32.732216 git.c:349 trace: built-in: git 'push' 'git@bitbucket.org:username/repo.git' 'master'
09:53:32.732514 run-command.c:341 trace: run_command: 'ssh' 'git@bitbucket.org' 'git-receive-pack '\''username/repo.git'\'''
09:53:39.665197 run-command.c:341 trace: run_command: 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '--progress'
09:53:39.665526 exec_cmd.c:134 trace: exec: 'git' 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '--progress'
09:53:39.666778 git.c:349 trace: built-in: git 'pack-objects' '--all-progress-implied' '--revs' '--stdout' '--thin' '--delta-base-offset' '--progress'
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 4.23 KiB | 0 bytes/s, done.
Total 7 (delta 4), reused 0 (delta 0)
To git@bitbucket.org:username/repo.git
0ef4905..91437d0 master -> master
How come git push
would be triggered only when the script is invoked manually and not when run via the crontab?
cron
send you any e-mail? – Arkadiusz Drabczyk Aug 31 '15 at 20:30$HOME
or$USER
. – myaut Aug 31 '15 at 20:30/var/log/syslog
e.g.Aug 31 22:44:01 laptop CRON[9364]: (username) CMD (/home/username/Sites/git/repo/commit.sh)
– anavarre Aug 31 '15 at 20:47