ssh-agent和crontab的 - 有什么好办法让这些见面吗? [英] ssh-agent and crontab -- is there a good way to get these to meet?

查看:90
本文介绍了ssh-agent和crontab的 - 有什么好办法让这些见面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的脚本,它每晚寄出SVN活动日志给开发者。到现在为止,我已经在同一台计算机的svn库上运行它,所以我没有担心验证,我可以只使用SVN的文件:///地址风格

I wrote a simple script which mails out svn activity logs nightly to our developers. Until now, I've run it on the same machine as the svn repository, so I didn't have to worry about authentication, I could just use svn's file:/// address style.

现在我在家用计算机上运行脚本,访问远程仓库,所以我不得不改变SVN + SSH://路径。使用ssh-键很好地建立了,我从来没有要为在正常情况下访问svn库输入密码。

Now I'm running the script on a home computer, accessing a remote repository, so I had to change to svn+ssh:// paths. With ssh-key nicely set up, I don't ever have to enter passwords for accessing the svn repository under normal circumstances.

不过,crontab中没有访问我的SSH密钥/ SSH代理。我读过有关这个问题在网络上几个地方,而且它也提到在这里,没有分辨率:

However, crontab did not have access to my ssh-keys / ssh-agent. I've read about this problem a few places on the web, and it's also alluded to here, without resolution:

<一个href=\"http://stackoverflow.com/questions/869589/why-ssh-fails-from-crontab-but-succedes-when-executed-from-a-command-line\">http://stackoverflow.com/questions/869589/why-ssh-fails-from-crontab-but-succedes-when-executed-from-a-command-line

我的解决办法是将它添加到脚本的顶部:

My solution was to add this to the top of the script:

### TOTAL HACK TO MAKE SSH-KEYS WORK  ###
eval `ssh-agent -s`

这似乎MacOSX的10.6下工作。

This seems to work under MacOSX 10.6.

我的问题是,如何可怕的是这一点,有没有更好的办法?

My question is, how terrible is this, and is there a better way?

推荐答案

在运行ssh代理-s,它将启动一个后台进程,你会需要稍后将其杀死。因此,最低是你的黑客更改为类似:

When you run ssh-agent -s, it launches a background process that you'll need to kill later. So, the minimum is to change your hack to something like:

eval `ssh-agent -s` 
svn stuff
kill $SSH_AGENT_PID

不过,我不明白这是如何破解工作。只需运行一个代理还没有运行的ssh-ADD将不会加载任何按键。也许MacOS的ssh-agent的行为是不同于它的<一个href=\"http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/ssh-agent.1.html\">manual页面说它。

这篇关于ssh-agent和crontab的 - 有什么好办法让这些见面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆