我有一个脚本要从一台服务器迁移到另一台服务器。在上一个它工作正常,但现在调用 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
笔记:
su
如myuser
运行脚本,一切正常root
的路径和 myuser
是一样的(完全一样)svn
使用二进制 其他一切都失败了,有什么方法可以查看
stderr
或其他一些输出,希望至少能看到一条简单的错误消息。附加信息:
谢谢@LazyBadger。只是看到错误终于让我明白了:
/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
防止从远程获得任何响应关于svn - 在 cron 作业中执行 svn info 对远程服务器失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23909016/