I am in the process of automating the backups from various servers to a central point then pushing those config changes into a git repo so I can track any changes over time. The rest of the scripts are working well, I can copy/rsync the files across the network to a central point. The last script is to get the config files to be put into/updated in repository. The script is as follows:



echo "  - running as user: $UID"

echo "backingup git config on $SERVERNAME"
echo ""

# check to see if root backup folder exists, otherwise create it.
if [ -d $GITROOT ]; then
    rm -rf $GITROOT
mkdir $GITROOT


echo "  - testing if home is where I think it should be!"
echo $HOME
echo "  - testing if it can see netrc"
tail $HOME/.netrc

git clone
cd HOH-config-backups

echo "  - copy Configuration Folders across"
cp -r $BACKUPROOTDIR/Configuration/* $GITROOT/HOH-config-backups/
cp -r $BACKUPROOTDIR/scripts $GITROOT/HOH-config-backups/

git add .
git commit -a -m "committing any new configuration changes!"
git push origin master

echo ""
echo "Git repo updated"

echo ""
echo "  - backing up this script"

if [ ! -d $FIREWIGSCRIPTLOC ]; then

cp /home/jon/gitConfig.sh  $FIREWIGSCRIPTLOC

The git repo is on a different machine in the network using Apache and HTTP-backend.exe (smart HTTP protocol). If I run this script as me "jon" it works. If I run it in crontab it fails. git uses the /home/jon/.netrc file for authentication:

login gitconfig
password 1234579

The log from crontab is:

TERM environment variable not set.
  - running as user: 1000
backingup git config on betty

  - testing if home is where I think it should be!
  - testing if it can see netrc
login gitconfig
password 1234579
got 08de5bc2b27b4940d9412256e76d5e3c3d9dbcdd
walk 08de5bc2b27b4940d9412256e76d5e3c3d9dbcdd
got be880f2d306778a538d592e7a02eb19f416612f7
got bd387e8def9f77aafa798bf53e80d949aba443e8
got 1bc1a59e12775841d4c59d77c63b8a73823138c2
walk bd387e8def9f77aafa798bf53e80d949aba443e8
Getting alternates list for
got 030512237bca72faf211e0e8ec2906164eac34f6
got 9bc2f575240bc1f61ff7d69777ce1a165d06b184
got b8400f7f01429104a9d4786a6bb1a16d293e37c1
got 2403b5bf611010e0b401f776f0e23b09ce744838
got 1a27944c48269ef3608a8f2466e43402d06faac0
got b686f45b7d57af4fa8ca0d528bb85216d6247e19
Getting pack list for
Getting index for pack ae881957c0f0e8c22eb6cc889a22ef78eb4ce6ff
Getting pack ae881957c0f0e8c22eb6cc889a22ef78eb4ce6ff
 which contains ff84d6d48e9326066438d167a10251218d612b3d
walk b686f45b7d57af4fa8ca0d528bb85216d6247e19
got 364e30daec17814073e668f490bb84af891fe1f7
got 23f6497e7f9b80e0d90adad73bd0407a0e5ac6ce
got 9e77c47574b5e23ea669afe0c23ab235e4917ee1
got 6654e0d328a216b3783e98c47206cb2d01b3353d
got 28821ffd437d2689ffb82c6e4b9c3f5372c95c4b
got 8c384a24f645389e4d4b08013c79e9e73a658342
got d203be0123736ee025ce20c081f1489098648dfc
got 1852603bf7709e71417d8ccec02390279d533642
got fb753a26b20b04694419fce8ecdaa8dbec105cf1
got 736028997cd84dd1c135f57e9d246674b9cd0b9d
got 7af836249e20096d0476a548d5be702a071cdd4b
got 240dc39d9db50df63073fc7927b2d002dfa0f54c
got 93abd36e3935a01011eb753b635a1a0e984bf31e
got c6269e28fecf4d8d0d98b9358aecb3acff02df44
got b0aa29432f73e64032682a351d436c24b14078ab
walk 240dc39d9db50df63073fc7927b2d002dfa0f54c
got 58fb66d9f35f8a5e32ff4683309c5f0c2a3a03c5
got 0da2def4de0565483cdbe6b87418ee2beb122e58
got 0f6a86c6f87ed52ad2ed01e5c6edd661d364930c
got 437a93d27b5bb89c739a0564a34a616e832c3ebe
got fe0385abe5c0acd8462268dac330bae00e934f1b
got 24259f8f5c5c9ee974a75fe3d1e07c02e3e20fe9
got d29f624bf1a5eceedaa86c10fee35f62747c7d04
got 0154e4c987132585ea7a92b77d02dba285512d6b

got eda8bf526567c25ee70addb2ad3c3c6aa57eac77
got 9f3d9d7262d66f9fa4f6a13b7c86199953f4bc4e
got 8e20881e19667aa22245d0598646991067455a4d
got abb1123145689b35eb19519952c71253ee45fa98
got dfeff593c79b4156ce2ce1adf043d0e80356488c
got e20c5b48b1d360e0bcf34189e3f3d2bbf23e92cc
got b13eb81cc274780322ecf786372320343926bec9
walk 8de83868b3fac748b0a55eba16c8f668ec852abb
got b5961421bbc42afe7a07cc1c8b615aba26ba74d7
got 2650ba819019df4193b482733e29ca79b29f3f2c
got b3111e1be8103e91803a97a817ed81f28025aca1
got b060be934d709684f5eb5dad3c03932a3589e864
got cf70d2043f081d7a4438e9d5a290a9f986c84060
got 80bf0f1cc836feab86d6935bb7968d8555a8d531
got da318d167920e34bc6573e4fc236249ccbbee316
got d82ac853d387b760149599e6e1ab96403f6ec672
got 0005f691d1f46550fdb4e56025f52e30a5b18cc2
Initialized empty Git repository in /tmp/git/HOH-config-backups/.git/
  - copy Configuration Folders across
Created commit 424df2f: committing any new configuration changes!
 3 files changed, 55 insertions(+), 1 deletions(-)
 create mode 100755 scripts/betty/gitConfig.sh
error: Cannot access URL, return code 22
error: failed to push some refs to ''

    Git repo updated

      - backing up this script
    cp: cannot create regular file `/mnt/backups/scripts/betty/gitConfig.sh': Permission denied

my crontab is:

# m h  dom mon dow   command
04 * * * * /home/jon/gitConfig.sh > /tmp/gitconfig.log 2>&1

I open it by doing:

$crontab -e

i.e. not as root.

Found out about the userid:

jon@betty:~$ id
uid=1000(jon) gid=1000(jon)  groups=4(adm),20(dialout),24(cdrom),46(plugdev),109(sambashare),114(lpadmin),115(admin),1000(jon)

here is my $HOME/.gitconfig file:

    name = Jon Hawkins
    email = jonathan1@houseofhawkins.com
  • It would seem there is a difference between the env crontab runs in and the user env. cannot tell why it will pull (which means it gets netrc file), but won't push in crontab but same script will if run by me. – Jon Nov 18 '10 at 9:52
  • 1
    Is there any reason you're not using Git+SSH? – Marco Ceppi Feb 16 '11 at 3:19
  • Can you post snippets of your Apache log showing an attempt from cron and a manual attempt? Maybe if the server is seeing something different and rejecting it that might provide a clue as to what's wrong. – ssweeny Feb 16 '11 at 8:25

I think the problem is in your .gitconfig. Have you set the user name in there? Also, if you're backing up to a remote machine, I'd highly recommend using SSH for this instead.

| improve this answer | |
  • added .gitconfig file. The backups are only over my local network, but thanks. – Jon Nov 17 '10 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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