Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cron作业自动推送到Git问题_Git_Bash_Cron_Bitbucket - Fatal编程技术网

Cron作业自动推送到Git问题

Cron作业自动推送到Git问题,git,bash,cron,bitbucket,Git,Bash,Cron,Bitbucket,我有一个cron作业设置,每天晚上运行bash脚本推送到Git cron作业被设置为root用户,我已通过:git config credential.helper store按照:(第二个答案)设置我的git凭据 bash脚本的代码非常简单 #!/bin/bash # Nightly push to Bitbucket # Set some variables DAY=$(date +%F); # Make sure we run as root if [ "$(whoami)" !=

我有一个cron作业设置,每天晚上运行bash脚本推送到Git

cron作业被设置为root用户,我已通过:
git config credential.helper store
按照:(第二个答案)设置我的git凭据

bash脚本的代码非常简单

#!/bin/bash

# Nightly push to Bitbucket

# Set some variables
DAY=$(date +%F);

# Make sure we run as root
if [ "$(whoami)" != "root" ]; then
    echo "Only root can do this.";
    exit 1;
else
    # Make sure we are in the right directory
    cd /hosting;
    # Now add any changes
    git add .;
    # Now commit
    git commit -m "$DAY Nightly";
    git push all;
fi;
只要我登录到服务器并以root用户身份运行它,它就可以正常运行

但是,它不会在指定的时间运行

Crontab-e设置为:
30 3***返回git>/dev/null 2>&1


我该怎么做才能让它工作?

首先,最好在cron选项卡中包含脚本的完整路径

30 3 * * * /opt/btg/back-to-git >/dev/null 2>&1
/opt/btg/back to git
替换为脚本的绝对路径。 然后尽量不要丢弃包含错误的输出:

30 3 * * * /opt/btg/back-to-git &>/home/your_user/btg.log 
这样,您可以在cron处理脚本时检测错误

您最后的评论表明bitbucket可能存在身份验证问题。为了确保以正确的方式推进,我建议始终在脚本中编写git的完整目标。所以试着使用

git-push——所有来源
而不是
git-push-all

当按下bitbucket时,请检查您的git设置以使用
ssh
而不是
https

您还可以指定要在
/root/.ssh/config

Host bitbucket
  HostName bitbucket.org
  User YOUR_USERNAME
  IdentityFile /root/.ssh/id_rsa
  IdentitiesOnly yes

什么是cronjob配置?在这里分享,看看是否有什么不对劲。此外,请检查.updated问题以包含作业,我将在BITT中查看该链接。这可能是关于如何调用脚本的问题:
返回git
是cron无法找到的。它是主目录中的脚本吗?然后确保您编写了完整的路径,以及执行它的二进制文件-->
/bin/bash/home/your_user/back to git
它是
/usr/bin
中的一个脚本,还具有执行权限,在脚本开头添加了类似于
(date;whoami)>/tmp/cron log.txt的内容,并在脚本假定失败后检查
/tmp/cron log.txt
的内容。如果文件在那里,作业确实会触发。如果没有,您就有一个cron问题(不是Git问题)。我使用了
Git-push-all
,因为我同时推送到github和bitbucket,还尝试了ssh。。。虽然github似乎可以工作,但bitbucket抛出了一个权限错误。我将把输出重定向到一个日志中(我在上次测试中删除了它),我开始越来越多地认为它是运行作业的用户。在日志中,我返回到ol'
警告:push.default未设置消息,然后显示
权限被拒绝(公钥)。致命:无法从远程存储库读取。请确保您具有正确的访问权限,并且存储库存在消息。两个回购协议都存在,都添加了我的id_rsa.pub。我想你在这里把我推向了正确的方向。看来我的问题是源于比特桶端。仅在github中使用ssh方法,效果很好。但是日志显示
警告:push.default未设置对于它,提交被推送。我必须看看bitbucket是否有办法添加一个
写入
访问密钥…如果我能找到更多关于这一点的信息,并且可以添加到这一点,我将保留您的答案作为未回答。。。但你肯定让我走对了路:),所以你赢得了赏金;)很高兴我能帮助您并将您推向正确的方向以解决您的需求:)