Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following shell script

#!/bin/bash
REPODIR=$HOME/work/repository/
cd $REPODIR
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/report-server.sh

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
add comment

2 Answers

make crontab job as:

*/1 * * * * nameoftheuser /home/nameoftheuser/Documents/./report-server.sh

or

*/1 * * * * nameoftheuser sh /home/nameoftheuser/Documents/report-server.sh

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/./report-server.sh'

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
add comment
up vote 0 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
add comment

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.