Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following shell script

var=`git fetch --dry-run 2>&1`
echo $var > $HOME/error.txt

I want to run my script every minute, so I edit crontab (via crontab -e) in order to run script from the current user.

*/1 * * * * /home/nameoftheuser/Documents/

From manual run - script works correctly. But running script from crontab (in the error.txt):

fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

Script file has 775 rights. I'm also checked git status and git config -l and that commands work correctly. git config -l correctly display remote origin url. Ubuntu 13.04 x64 with latest updates.

What should I do to work with git from crontab?

share|improve this question
up vote 1 down vote accepted

Git can't authorize when asking remote about changes in master because when I generate ssh-key I protect it with a passphrase.

So I just regenerate key without passphrase and script works perfectly.

share|improve this answer

make crontab job as:

*/1 * * * * nameoftheuser /home/nameoftheuser/Documents/./


*/1 * * * * nameoftheuser sh /home/nameoftheuser/Documents/

Or if you want to do it as you posted, you need to add alias at the end of /etc/bash.bashrc to that script like:

alias report-server='/home/nameoftheuser/Documents/./'

and then you can add cron job as:

*/1 * * * * root report-server
share|improve this answer
None of these approaches doesn't work. They doesn't even create error.txt in the Home folder. I need to execute script as user – mef_ Jul 11 '13 at 7:34
make sure you do /etc/init.d/cron restart after every change to cron – mirkobrankovic Jul 11 '13 at 7:56
Oh, sorry. I just realized that problem is not in the crontab. Somehow git can't authorize when asking remote about changes in master. – mef_ Jul 11 '13 at 8:03
Oh then I shell delete this :) – mirkobrankovic Jul 11 '13 at 8:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .