I was trying to create a cronjob with a task to do a git pull every minute to keep my production site in sync with my master branch.
The git pull needs to be done by the system user nobody, due to the permissions problem. However it seems that the nobody account is not allowed run commands. So I have to create tasks as the root user.
The crontab entry I tried:
*/1 * * * * su -s /bin/sh nobody -c 'cd ~heilee/www && git pull -q origin master' >> ~/git.log
It doesn't work, and I don't know how to debug it.
Could anyone help?
UPDATE1: the git pull command itself is correct. I can run it without errors.
Solution:
*/1 * * * * su -s /bin/sh nobody -c 'cd ~dstrt/www && /usr/local/bin/git pull -q origin master'
While you do need to figure out how to get the update to work in the first place, you'd be far better off using a hook from the upstream to make it go. You can do this simply with curl from a post-commit hook or if you're using github, just use a post-receive hook on their side.
*/1 * * * * su -s /bin/sh nobody -c 'cd /home/heilee/src/project && /usr/bin/git pull origin master'
This corrects a couple errors that prevented the accepted answer from working on my system (Ubuntu >10.04 server). The key change seems to be the -q after the pull rather than before. You won't notice that your pull isn't working until you tail the /var/log/syslog file or try to run your non-updated production code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With