Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

To backup my sql database I have a cron job running that makes a mysql dump. Now I want to create another cron job that commits this dump to the repo, the problem now is that it doesn't work.

In the cron log I see the line where the command gets run but nothing is committed.

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
MAILTO=root
HOME=/

49 16 * * * cd /path/to/backup/folder/ && /usr/local/bin/git commit -am "Updating DB backup"

This is what I put in crontab -e. I also tried this in /etc/crontab, where I put root as user and that works but only as root user which is a problem because of the git post-commit hook that does push after something is commited. Since only my user is allowed to push this doesn't work when root doest the commit.

Since its working with the root user I'm thinking it's a permissions problem, but permissions of what? These commands work in normal command line.

When catching the stdout and stderr I get the following in the log.

Permission denied (publickey).^M
fatal: The remote end hung up unexpectedly

so it doesn't really runs as my user or can't find the key?

share|improve this question
    
Please clarify your question. You're using push and commit interchangeably and they have nothing in common. For example, I could see a problem with push if it where pushing to a remote ssh target as root, just like root access to any server might be blocked. If you just focus on commit, that's updating the local index, which you likely own e.g. .git/, so permissions shouldn't matter at all there. Also please provide the cron logs surrounding the incident. –  ppetraki Mar 6 '12 at 16:16
    
I got it working by creating a new key without passphrase for the root user and set up the cron job for him. –  dazz Mar 8 '12 at 10:19

2 Answers 2

The format for your cron file (which is what you get when you type crontab -e) is different from the system cron file. You don't need to specify user in the user cron file, it is automatically run as you. Try:

49 16 * * * cd /path/to/backup/folder/ && /usr/local/bin/git commit -am "Updating DB backup"

I would also suggest catching stdout and stderr so that you can actually see what the commit has done, for example:

49 16 * * * cd /path/to/backup/folder/ && /usr/local/bin/git commit -am "Updating DB backup" >> /path/to/logfile 2>&1

Edited to add: Now that you've shown the output from stdout/stderr, the problem is clear. ssh is not finding your keys, which is likely due to you setting

HOME=/

It should probably be something like

HOME=/home/me

Alternatively, you could probably just leave it unset.

share|improve this answer
    
added the output to the question –  dazz Mar 7 '12 at 10:47
    
doesn't fix it, i also add /home/me/.ssh to the PATH –  dazz Mar 7 '12 at 15:39

You probably are setting the crontab using another user that not you. Check if you are doing "sudo crontab -e" and try just "crontab -e" with your user or whoever is the owner of the git and files.

This sorted me out so maybe it will work for you too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.