2

I want to commit some file changes using a cron job calling a script with the following line in roots crontab

0 * * * * cd /files/ && ./backup.sh >/tmp/cronlog 2>/tmp/cronerror

the script looks as follows:

#!/usr/bin/env bash

… prepare the files for the backup …

echo "commit changes …"
git add -u
git commit -m "backup"
git push

Prior to the cron setup I've also set user.email and user.name for the root user and I've checked that the script runs if I call if from the command line.

But in /tmp/cronerror I receive the following well known message.

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
…

I've also tried setting HOME=/root in the script but this doesn't seam to make a difference.

Is there a way of telling the git command where to find the global git-config when running in a cron job?

white_gecko
  • 4,808
  • 4
  • 55
  • 76
  • Interesting. Did you use `HOME=/root; export HOME` or `export HOME=/root`? (Or put `HOME=/root` in front of each git command, but that's the long way.) – torek Aug 05 '14 at 15:16
  • I just wrote `HOME=/root` in a line before the `echo`, should I've used `export`? – white_gecko Aug 06 '14 at 09:47
  • I've now also added an `echo $HOME`, which already is set to `/root`. And even putting `HOME=/root` in front of each git command doesn't change the situation. – white_gecko Aug 06 '14 at 10:05
  • OK, so it's not that `$HOME` is wrong, it's something else. What else, I don't know. It's interesting that storing the config in the local repository works. – torek Aug 06 '14 at 16:52

1 Answers1

2

My solution is to use git config … without --global option which stores the configuration in the current repository, where git is able to find it.

white_gecko
  • 4,808
  • 4
  • 55
  • 76