【发布时间】:2014-05-29 10:18:52
【问题描述】:
我有一个脚本要从一台服务器迁移到另一台服务器。在前一个上它运行良好,但现在在 cronjob 中运行时调用 svn info 失败。如果我 su 与 cron 使用的同一用户相同,则相同的呼叫可以正常工作。只有当它是http:// url 时调用才会失败;对file:/// url 的 info 调用工作完美。
这是安装了最少软件的普通 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二进制文件 - 经过验证的 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
【问题讨论】: