SVN 更新 Crontab Linux
我想弄清楚如何通过 Linux 的 cron 运行 SSH 命令。我想运行的命令是:
svn update /path/to/working/dir
类似于:
*/1 * * * * root ssh svn update /path/to/working/dir
有人知道我需要用 cron 行做什么吗?
编辑:我不需要它是 SSH,只需要在与 cron 相同的服务器上运行 svn update 到工作目录。
编辑2:我正在寻找的是:
*/1 * * * * svn update /path/to/your/working/copy
我的措辞不正确,关于SSH询问得太具体,所以我给出了专门通过SSH谈论cron的答案,但如果有人想知道如何在本地执行它,你就不会'不需要 SSH。
I am trying to figure out how to run a SSH command via cron for linux. The command I want to run is:
svn update /path/to/working/dir
Something like:
*/1 * * * * root ssh svn update /path/to/working/dir
Anyone know what I would need to do with the cron line?
EDIT: I don't need it to be SSH, just need to run svn update on the same server as cron to the working directory.
EDIT 2: What I was looking for was:
*/1 * * * * svn update /path/to/your/working/copy
I worded it incorrectly though, asking too specific about SSH, so I awarded the answer that talks about cron via SSH specifically, but if anyone wants to know how to do it locally, you don't need SSH.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须比较环境变量。我编写了一个简单的 bash 脚本来为我执行此操作:
并将其保存在 /home//crontest.sh
然后您手动执行代码并将结果写入文件中:
然后在您的 crontab 中:
之后您有两个文件中,您可能会发现环境变量之间存在一些差异。
svn 和 cron 问题的解决方案是将 svn update 的 bash 脚本中的环境变量设置为手动获得的环境变量,它应该看起来像这样(第 2 部分>/dev/null 和 exit 0 非常重要):
将此脚本写入 for 例如。 /etc/init.d/skrypty/cron.sh
然后你只需输入你的 crontab (我已经以 root 身份完成了)
You must compare the environment variables. I've wrote a simple bash script to do that for me:
And save it in /home//crontest.sh
Then you execute the code by hand and write the result into a file:
Then in your crontab:
After that you have two files, you will probably see that there are some differences between the environment variables.
The solution to the svn and cron problem is to set the environment variables in bash script of svn update to those obtained by hand it should look something like this (parts 2>/dev/null and exit 0 ARE VERY IMPORTANT):
Write this script in for eg. /etc/init.d/skrypty/cron.sh
Then you just put in your crontab (i've done it as root)
您需要将主机名(以及用户名,除非您想以 root 身份登录)传递给 SSH:
另请参阅
ssh --help
了解更多信息。请注意,您需要使用 SSH 输入密码,除非您已设置 SSH 才能使用无需密码即可登录
You need to pass the host name (and also the username, unless you want to log in as root) to SSH:
Also see
ssh --help
for more information.Note that you'd need to input your password with SSH, unless you've setup your SSH to be able to log in without password
我遇到了同样的问题,我以
root
用户身份编辑了 crontab。我的 home (/home/myname/project
) 目录下有工作副本,我以myname
用户身份编辑了 crontab 并且它有效。0 22 * * * bash /home/myname/svn.sh
svn.sh
有以下行#!/bin/sh
svn up /home/myname/project
I have faced the same issue where I had edited crontab as
root
user. I have working copy under my home (/home/myname/project
) directory and I did edit crontab asmyname
user and it worked.0 22 * * * bash /home/myname/svn.sh
svn.sh
has the following lines#!/bin/sh
svn up /home/myname/project