threads / discuss / 24221

[OT?] Executing Git from bash script invoked by cron

Subject: [OT?] Executing Git from bash script invoked by cron

## tl;dr

7 messages between Jun 28, 2010 and Jul 3, 2010.

replies: 6people: 5as markdown or json

Johannes Schneider· Jun 28, 2010, 21:00 UTC · lore
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,

I try to mirror my local git repository. Therefore I created a bash script. This script, executed form the command line, works fine.

But the same script executed by cron, does not work. Git push does simply nothing. No output, no push, nothing. But git log and git --version works...

I tried to google the problem, but couldn't not find anything useful. Any hints are welcome.

Ubuntu 64Bit git version 1.7.0.4 cron 3.0pl1-106ubuntu5

Thanks,
Johannes
- -- 
Johannes Schneider - blog.cedarsoft.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBAgAGBQJMKQ2GAAoJEAytD9R7Qv6dRmIH/3YqxEMRDLeHcLfsH0JYBdOT NG2e7mMjiYg2akQOsXSN4iN1iMrRfj/gp9udd7QM4p8W06xlv0wftOC87IKZKDtp DujAYB6hHMtHYkVrWV9KuP+ptuaZDvhgti+8DvfAKGuXbRa0xs4CcRCclLLNrj6x tqJJZatdVZgvEDBePWVcTJfglJf+2lozxBXvTkat8mjEGCYDuUfvG37yimSETZHT wJITWGi3BdMG5m6xHOHDYp4IHuGw2sfWYAN3EE7dS6m2P7/l/VRM18PsAWFM3j1Q Axv57mkJu1ea9tj54W7I7kJCHDC5TZDf9FXSPPOMY1t1qzgtGfB7tfQMDamHIYY= =LRSS -----END PGP SIGNATURE-----

Sverre Rabbelier· Jun 28, 2010, 21:05 UTC · re: Johannes Schneider · lore

Re: [OT?] Executing Git from bash script invoked by cron

Heya,

On Mon, Jun 28, 2010 at 23:00, Johannes Schneider <mailings@cedarsoft.com> wrote:

> But the same script executed by cron, does not work. Git push does
> simply nothing. No output, no push, nothing.

Very silly question, does the cron version have anything to push? IIRC 'git push' doesn't output anything if there's nothing to push? Try running 'git push --verbose' instead.

-- 
Cheers,

Sverre Rabbelier
Marc Weber· Jun 28, 2010, 21:17 UTC · re: Johannes Schneider · lore

Re: [OT?] Executing Git from bash script invoked by cron

Excerpts from Johannes Schneider's message of Mon Jun 28 23:00:56 +0200 2010:
Show 14 quoted lines
> Hash: SHA1
> 
> Hi,
> 
> I try to mirror my local git repository.
> Therefore I created a bash script. This script, executed form the
> command line, works fine.
> 
> But the same script executed by cron, does not work. Git push does
> simply nothing. No output, no push, nothing.
> But git log and git --version works...
> 
> I tried to google the problem, but couldn't not find anything useful.
> Any hints are welcome.
What do you do in such cases? Make sure you log both: stdout and stderr.

a) sh -c 'your quoted command &> /tmp/logfile'

b) if this still does not work use strace:
sh -c 'strace -f-o /tmp/strace.log your quoted command &> /tmp/logfile'
Then you know how much is happening.

You may also want to check that the environment is the same. Eg export > file to create a file containing your environment. Then source it in the cron job line somehow.

I'm not using cron that often so the solution could be simpler.
Marc Weber
Sverre Rabbelier· Jun 28, 2010, 21:22 UTC · re: Marc Weber · lore

Re: [OT?] Executing Git from bash script invoked by cron

Heya,
[Mark, please don't cull the cc list]
On Mon, Jun 28, 2010 at 23:17, Marc Weber <marco-oweber@gmx.de> wrote:
> b) if this still does not work use strace:
>
> sh -c 'strace -f-o /tmp/strace.log your quoted command &> /tmp/logfile'

If you have to result to strace with git, it will probably then be helpful to use GIT_TRACE=1, it will at least tell you what commands are being invoked by git in a semi-human-readable format.

-- 
Cheers,

Sverre Rabbelier
Johannes Schneider· Jul 3, 2010, 17:19 UTC · re: Marc Weber · lore

Re: [OT?] Executing Git from bash script invoked by cron

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 06/28/2010 11:17 PM, Marc Weber wrote:
> sh -c 'your quoted command &> /tmp/logfile'
> 
> b) if this still does not work use strace:

That is it. Thanks. Of course, git writes to stderr. And I did not redirect it properly. I don't understand the details, but this line is working now:

sh -c 'myscript' >> logfile 2> err

The problem - by the way - is related to ssh authentification... But that is another issue...

But here comes my question: Obviously all output created by git push is written to stderr. I'd expected that most of the content will end up in stdout. But I am sure there is a good reason for it - so I just accept it ;-)

Thanks,
Johannes
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBAgAGBQJML3E0AAoJEAytD9R7Qv6dZ5cIANpYYu5isncB3LcLaQgURQmP esxkrtAVrcghItv+KkSts+qb8IBlEmA1mkzMYpmgVn6M/CQxh3atlaDsTbNtznAA eZVJwXqQwoPlJS8ZvoDcSdldcL5Nmi+nyJgg408y5j3GB4AEt8IihxYVW7Xs0pFQ GdBOSjV/TK1PEjcP7dNYJ9MSdUFA6Z7GrywRKQwlRZ4C611wCBpEoAeD0S1vcJcl B78DTIqB+P3VF+mLW3u2LRXUdp3+tM2uutGR7DkG6GVomHJkwb5zAGXU4AmwHt2L OdDwPAAZ5OzAgfyqLZ4YrOMv9Pg8sOjj+YLfljLUIXB/muJPACqNljv+liCmrac= =X2Lj -----END PGP SIGNATURE-----

Ramkumar Ramachandra· Jun 28, 2010, 21:43 UTC · re: Johannes Schneider · lore

Re: [OT?] Executing Git from bash script invoked by cron

Hi Johannes,
Johannes Schneider writes:
Show 7 quoted lines
> I try to mirror my local git repository.
> Therefore I created a bash script. This script, executed form the
> command line, works fine.
> 
> But the same script executed by cron, does not work. Git push does
> simply nothing. No output, no push, nothing.
> But git log and git --version works...

Perhaps you're not executing that `git push` as the same user, and therefore there's some problem reading the config files to determine where to push to? I really can't tell much else without some output.

-- Ram
Matthieu Moy· Jun 29, 2010, 06:24 UTC · re: Johannes Schneider · lore

Re: [OT?] Executing Git from bash script invoked by cron

Johannes Schneider <mailings@cedarsoft.com> writes:
> But the same script executed by cron, does not work. Git push does
> simply nothing. No output, no push, nothing.
> But git log and git --version works...

One common problem with cron jobs is that you don't have the same $PATH in your shell and in cron. If you have no output at all, I'd say you didn't reach the line where git is executed in your script.

Try to add a
  set -x
at the beginning of your script to see what it's doing.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads