gpt4 book ai didi

svn - 在 cron 作业中执行 svn info 对远程服务器失败

转载 作者:行者123 更新时间:2023-12-04 19:38:11 25 4
gpt4 key购买 nike

我有一个脚本要从一台服务器迁移到另一台服务器。在上一个它工作正常,但现在调用 svn info在 cronjob 中运行时失败。如果我 su,同样的调用工作正常作为同一用户cron用途。只有当它是 http:// 时调用才会失败网址;信息调用 file:///网址完美运行。

这是安装了最少软件的普通 CentOS 6.5 服务器 (svn 1.6.11)

#cron 
*/1 * * * * myuser /opt/update-stuff.sh >> /opt/update-stuff.log
#/1 is for testing this right now... got tired of waiting

脚本看起来有点像这样,但要长得多。只有一个调用失败
# update-stuff.sh
# this call just outputs blank. I can't tell what is failing
echo ==[ remote test ]==
svn info http://svn.corp.com/svn/repo1

# this call works just fine. not an auth test, just to show svn is working
echo ==[ local test ]==
svn info file:///opt/mirrors/repo1

笔记:
  • 如果我 sumyuser运行脚本,一切正常
  • root 的路径和 myuser是一样的(完全一样)
  • 我将脚本简化为仅这两行,仍然得到相同的
  • 验证相同svn使用二进制
  • 已验证的 cron 实际上是以该用户身份运行的:D

  • 其他一切都失败了,有什么方法可以查看 stderr或其他一些输出,希望至少能看到一条简单的错误消息。

    附加信息:

    谢谢@LazyBadger。只是看到错误终于让我明白了:
  • Cron 没有设置用户的环境。
  • 看来(虽然我不是专家)/etc/bashrc和其他人没有运行

  • 解决方案:

    最终得到错误后,我尝试强制 svn 使用 u/p。这有效,但它提示保存身份验证信息。所以我编辑 .subversion/servers .还在提示。所以添加一个 set到脚本。查看未设置环境变量(错误的主页)。去谷歌!然后到一个窃取 the answer that helped me from serverfault.com 的网络爬虫。
    # *  *  *  *  * user-name command to be executed

    # use root user, and 'su' to get the same environment as if the user logged in
    */5 * * * * root su - myuser /opt/update-stuff.sh >> /opt/update-stuff.log 2>&1

    最佳答案

    无关

  • */1在 cron 中是 坏主意 (tm)
  • 为了检测到远程仓库的新提交,您可以使用比 svn info 更轻量级和更容易解析的 svn 命令。
  • 成功操作 file:///协议(protocol)没有任何意义:基于文件的访问不使用任何身份验证|授权方法和(或)特定于 SVN 的 ACL,这可以(理论上)阻止访问 http-repo

  • 相关
  • 为了查看日志中的所有输出,重定向 svn info 的 stderr另外,像 svn info http://svn.corp.com/svn/repo1 >> /opt/update-remote.log 2>&1
  • 只是想法。在“某些情况”下,您的连接超时可能超过 1 分钟,并且 */1防止从远程获得任何响应
  • 围绕你的第一个音符。无法记忆在某些用户下执行的 cron-job 和 shell 中的同一用户的环境差异,但它们可能存在
  • 关于svn - 在 cron 作业中执行 svn info 对远程服务器失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23909016/

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