SVN 更新 Crontab Linux

发布于 2024-12-01 16:28:16 字数 468 浏览 0 评论 0原文

我想弄清楚如何通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千鲤 2024-12-08 16:28:16

您必须比较环境变量。我编写了一个简单的 bash 脚本来为我执行此操作:

#!/bin/bash
env
echo $PATH
type -a svn
cd /home/<username>
svn info
exit 0

并将其保存在 /home//crontest.sh

然后您手动执行代码并将结果写入文件中:

/home/<username>/crontest.sh > /home/<username>/hand_env

然后在您的 crontab 中:

* * * * * /home/<username/crontest.sh > /home/<username>/cron_env

之后您有两个文件中,您可能会发现环境变量之间存在一些差异。

svn 和 cron 问题的解决方案是将 svn update 的 bash 脚本中的环境变量设置为手动获得的环境变量,它应该看起来像这样(第 2 部分>/dev/null 和 exit 0 非常重要):

#!/bin/bash

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X$
export MAIL=/var/mail/root
export _=/usr/bin/env
export PWD=/home/tv
export LANG=en_US.UTF-8
export HOME=/home/tv
export SHLVL=2
export LOGNAME=root
#export LESSOPEN=| /usr/bin/lesspipe %s
#export LESSCLOSE=/usr/bin/lesspipe %s %s
export SHELL=/bin/bash
svn update https://localhost/svn /var/www/<dir> 2>/dev/null
exit 0

将此脚本写入 for 例如。 /etc/init.d/skrypty/cron.sh
然后你只需输入你的 crontab (我已经以 root 身份完成了)

* * * * * /etc/init.d/skrypty/cron.sh >/dev/null 2>&1

You must compare the environment variables. I've wrote a simple bash script to do that for me:

#!/bin/bash
env
echo $PATH
type -a svn
cd /home/<username>
svn info
exit 0

And save it in /home//crontest.sh

Then you execute the code by hand and write the result into a file:

/home/<username>/crontest.sh > /home/<username>/hand_env

Then in your crontab:

* * * * * /home/<username/crontest.sh > /home/<username>/cron_env

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):

#!/bin/bash

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X$
export MAIL=/var/mail/root
export _=/usr/bin/env
export PWD=/home/tv
export LANG=en_US.UTF-8
export HOME=/home/tv
export SHLVL=2
export LOGNAME=root
#export LESSOPEN=| /usr/bin/lesspipe %s
#export LESSCLOSE=/usr/bin/lesspipe %s %s
export SHELL=/bin/bash
svn update https://localhost/svn /var/www/<dir> 2>/dev/null
exit 0

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)

* * * * * /etc/init.d/skrypty/cron.sh >/dev/null 2>&1
流星番茄 2024-12-08 16:28:16

您需要将主机名(以及用户名,除非您想以 root 身份登录)传递给 SSH:

*/1 * * * * root ssh user@hostname svn update /path/to/working/dir

另请参阅 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:

*/1 * * * * root ssh user@hostname svn update /path/to/working/dir

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

偷得浮生 2024-12-08 16:28:16

我遇到了同样的问题,我以 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 as myname user and it worked.

0 22 * * * bash /home/myname/svn.sh

svn.sh has the following lines

#!/bin/sh
svn up /home/myname/project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文