gpt4 book ai didi

ruby - 备份所有 git repos 并使用相同脚本设置 cron 作业的脚本

转载 作者:太空宇宙 更新时间:2023-11-04 10:43:24 28 4
gpt4 key购买 nike

我想设置一个脚本并使用 cronjob 来备份所有存储库。

仅供引用...

RVM版本:1.20.13,Ruby版本:1.9.3p429,Gem版本:1.8.25,Bundler版本:1.3.5,Rake版本:10.0.4,GitLab信息版本:5.3.0

我尝试了下面的方法,但它们没有用。请帮我设置所需的 cronjob。当我手动执行命令时,它们运行良好。

方法一:

#!/bin/bash

cd /home/git/gitlab/

bundle exec rake gitlab:backup:create RAILS_ENV=production

错误:

bundle: command not found

方法二:

#!/bin/sh

cd /home/git/gitlab/

bundle exec rake gitlab:backup:create RAILS_ENV=production

错误:

/bin/sh: bundle: command not found

方法三:

10 10 * * * cd /home/git/gitlab && PATH=$PATH:$/home/git/.rvm/gems/ruby-1.9.3-p429/bin:/home/git/.rvm/gems/ruby-1.9.3-p429@global/bin:/home/git/.rvm/rubies/ruby-1.9.3-p429/bin:/home/git/.rvm/bin::/home/git/.rvm/rubies/ruby-1.9.3-p429/.irbrc bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=1 >> /tmp/git_bck.log 2>&1

错误:

/home/git/.rvm/gems/ruby-1.9.3-p429@global/bin/ruby_noexec_wrapper:7:in `require': no such file to load -- rubygems (LoadError) from /home/git/.rvm/gems/ruby-1.9.3-p429@global/bin/ruby_noexec_wrapper:7

最佳答案

你需要做两件事:

1) 重新创建与命令行中相同的环境。为此,在命令行中运行 env,然后在 cron 中运行 env 并输出到 shell,比较其中的 2 个

2) source rvm in(查看你的 .bashrc 或你的 shell 中的任何 rc)。

这两件事应该允许您从 cron 运行脚本。您可以将它们放在脚本的开头。

关于ruby - 备份所有 git repos 并使用相同脚本设置 cron 作业的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34082323/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com