3

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?

2 Answers 2

2

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.

0

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
4
  • 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_
    Commented Jul 11, 2013 at 7:34
  • make sure you do /etc/init.d/cron restart after every change to cron Commented Jul 11, 2013 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_
    Commented Jul 11, 2013 at 8:03
  • Oh then I shell delete this :) Commented Jul 11, 2013 at 8:23

You must log in to answer this question.

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