4

I look into a lot of answers about this subject, but something is wrong here, let me explain. I create this script, to make my cron cleaner :)

#!/bin/bash

cd /home/valter.silva/Development/git/valter/ 
/usr/bin/git add -A 
/usr/bin/git commit -am "update `date`"
/usr/bin/git push

Then add it at my cron, valter.silva's cron, not my root cron:

00 * * * * /home/valter.silva/Development/git/valter/scripts/git/sync.sh

Restart my cron

sudo service cron restart
cron stop/waiting
cron start/running, process 6047

Aaand .. nothing happens..

But if I execute my script in command line, everything works fine. I know for a fact that sometimes if you don't put the whole path at cron scripts won't work correctly. And that I should use my cron to do that, not root's cron.

So what's wrong here ? Any ideas ? Thank you!

udpate

I follow Terdon suggestion, into log the operation, but it seems everything is okay, but not the push process though. Why ?

[master ad5d001] update Fri Aug  9 11:00:01 BRT 2013
 9 files changed, 1224 insertions(+), 364 deletions(-)
 create mode 100644 scripts/centreon/4.answers~
 create mode 100644 scripts/centreon/6.importing database
 create mode 100644 scripts/centreon/6.importing database~
 create mode 100755 scripts/centreon/7.upgrade.sh
 create mode 100755 scripts/centreon/7.upgrade.sh~
 create mode 100644 scripts/centreon/8.answers
 create mode 100644 scripts/centreon/8.answers~
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
4
  • How did you add this to your user's crontab (you should use crontab -e)? What does crontab -l report? You can try to add SHELL=/bin/bash and MAILTO="valter.silva" into your user's crontab. Especially the latter might give you some error messages in your local mail (/var/spool/mail/valter.silva) if local mail system is working. And IMHO there is no need to restart the cron service.
    – mpy
    Aug 9, 2013 at 12:09
  • crontab -e, not sudo crontab -e. The crontab -l is exactly that entry that I post it, there's only this entry in my cron. Aug 9, 2013 at 12:44
  • 1
    Is the remote git server protected by an ssh key with a password by any chance ? Jun 24, 2014 at 6:00
  • Did you ever figure it out? Arrived here by googling. Wondering if you ever fixed it. Dec 12, 2016 at 22:18

3 Answers 3

2

To add up, I have simplified the links, so it is more readable for someone looking for an answer based on huti's blog post.

So for your sync.sh I would add -u origin master for the push:

#!/bin/bash

cd /home/valter/git-project/
/usr/bin/git add -A 
/usr/bin/git commit -am "Daily update"
/usr/bin/git push -u origin master

Make sure you script can be executed by bash:

sudo chmod 765 ~/sync.sh

Then you can add a line to the /etc/crontab:

sudo nano /etc/crontab # To edit the file
01 18  *  *  * root  /home/valter/sync.sh

Be sure to reboot for the cron job to take effect, Now your script will be run every day at 18:01. If there is no modification, nothing will be pushed though.

1

I am not an git master, but I make some git tests on my local git test repo. When I run git push, then output is:

fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

git remote add <name> <url>

and then push using the remote name

git push <name>

Q: Have you configured remote repository using git remote add command? If yes, try run git push with name of remote repository. If no, configure one, or use git push with remote repository url on command line (git push git://host.xz[:port]/path/to/repo.git/ ).

1
  • I did configure with git remote add, I will look into it. Aug 19, 2013 at 14:00
0

Why would you expect something to happen? You have told cron to run your script every hour, on the hour. If you modified your crontab at, say, 13:02 nothing is going to happen until 14:00.

Try waiting a while, until the time hits XX:00, your script should run. Oh, and there is no need to restart cron, it will read the new crontab and run it next time it should be run.

If you have waited long enough and your script is still not being run, try redirecting the error output to check if anything is happening:

00 * * * * /home/valter.silva/Development/git/valter/scripts/git/sync.sh 2> /home/valter.silva/error.txt

Also try setting up a dummy cron job to see if that works:

00 * * * * date > /home/valter.silva/date.txt
4
  • I'm trying to run this over a week now, trying to figure out what is happening to not commit my changes. Aug 9, 2013 at 12:42
  • @ValterHenrique see updated answer for a couple of suggestions.
    – terdon
    Aug 9, 2013 at 12:53
  • Ok, terdon, will do that. I'm cloning my repo in a different computer now :) Aug 9, 2013 at 13:01
  • I update my post, could you please take a look ? Aug 9, 2013 at 14:23

You must log in to answer this question.

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