当通过cron从脚本调用时,git不会产生输出
我有一个脚本git-Test
转到本地git repo并调用git Shortlog
以跟踪最近的更改。为了进行测试目的,我只使用了以下行:
#!/bin/bash
cd /myrepo.git
result="$(/usr/bin/git shortlog -3)"
echo "$(date):$result" >> /tmp/git-log
crontab条目是
* * * * * /home/username/git-test >> /tmp/cron-output 2>&1
在所有脚本工作之后都从控制台和从Cron开始使用的,可以执行简单的ls -lh
而不是git命令。但是它没有用git命令从cron呼叫。因此问题必须是git。
我尝试了:
- 从终端调用脚本 - >做得很好,
- 从上面的 - >在
/tmp/git-log
中没有git输出,也没有/tmp/cron-o-Output中的
- 错误)“ 而不是
$(/usr/bin git shortlog -3)
- >做 - cron的良好调用脚本,直接用
git shortlog -3&gt直接写入文件>/tmp/git-log
- >/tmp/git-log
- 将git
cd /myrepo.git; git shortlog -3>>> /tmp/cron-ofput
可能是什么?
任何想法
I've got a script git-test
going to a local git repo and calling git shortlog
to keep track of recent changes. For testing purposes, I just used these lines:
#!/bin/bash
cd /myrepo.git
result="$(/usr/bin/git shortlog -3)"
echo "$(date):$result" >> /tmp/git-log
the crontab entry is
* * * * * /home/username/git-test >> /tmp/cron-output 2>&1
After all the script IS WORKING called from console and IS WORKING from cron with doing a simple ls -lh
instead of the git command. But it IS NOT WORKING called from cron with the git command. So the problem must be git.
I tried:
- calling script from terminal -> doing fine, getting git short logs
- calling script from cron, like above -> no git output in
/tmp/git-log
and no errors in/tmp/cron-output
- calling script from cron, but doing a
$(ls -lh)"
instead of$(/usr/bin git shortlog -3)
-> doing fine - calling script from cron, writing to a file directly with
git shortlog -3 >> /tmp/git-log
-> no git output in/tmp/git-log
and no errors in/tmp/cron-output
- putting the git
cd /myrepo.git;git shortlog -3 >> /tmp/cron-output 2>&1
directly in crontab -> no output and no errors in/tmp/cron-output
Any Ideas what the problem might be?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Git Shortlog
具有怪异的“功能”。 它已记录为 ,但是“功能” 感到惊讶的是,它经常被错过:您从crontab运行的stdin已将其重定向到文件(嗯,
/dev/dev/null
,但“不是终端”),因此您可以点击此功能:git Shortlog
读取从stdin登录,这是空的,因此其输出为空。治愈方法是为其提供适当的
git log -pretty =简短
输出,如文档中的概述行所示。(为什么“功能”?我不知道。我根本不了解这种行为。)
git shortlog
has a weird "feature". It is documented, right up front in the manual page, but the "feature" is so surprising that it is often missed:Your run from crontab has stdin redirected to a file (well, to
/dev/null
, but "not a terminal") so you hit this feature:git shortlog
reads the log from stdin, and that's empty, so its output is empty.The cure is to feed it the appropriate
git log --pretty=short
output, as seen in the SYNOPSIS line in the documentation.(Why the "feature"? I have no idea. I don't understand this behavior at all.)