简体   繁体   English

SVN更新Crontab Linux

[英]SVN Update Crontab Linux

I am trying to figure out how to run a SSH command via cron for linux. 我试图弄清楚如何通过cron for linux运行SSH命令。 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? 有人知道我需要对cron行做什么吗?

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. 编辑:我不需要它是SSH,只需要在与cron相同的服务器上运行svn update到工作目录即可。

EDIT 2: What I was looking for was: 编辑2:我正在寻找的是:

*/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. 不过,我的措词有误,对SSH的询问过于具体,因此我专门给出了通过SSH谈论cron的答案,但是如果有人想知道如何在本地进行SSH,则不需要SSH。

You must compare the environment variables. 您必须比较环境变量。 I've wrote a simple bash script to do that for me: 我写了一个简单的bash脚本来为我做这件事:

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

And save it in /home//crontest.sh 并将其保存在/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: 然后在您的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 ): svn和cron问题的解决方案是将svn update的bash脚本中的环境变量设置为手工获取的环境变量,它应该类似于以下内容(第2部分> / dev / null并退出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

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然后,您只需放入crontab(我已经以root身份完成了)

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

I have faced the same issue where I had edited crontab as root user. 我曾以root用户身份编辑crontab时遇到同样的问题。 I have working copy under my home ( /home/myname/project ) directory and I did edit crontab as myname user and it worked. 我的主目录( /home/myname/project )下有工作副本,并且确实以myname用户身份编辑了crontab,并且可以正常工作。

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

svn.sh has the following lines svn.sh具有以下几行

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

You need to pass the host name (and also the username, unless you want to log in as root) to SSH: 您需要将主机名(以及用户名,除非要以root用户身份登录)传递给SSH:

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

Also see ssh --help for more information. 另请参阅ssh --help以获得更多信息。

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 请注意,除非已将SSH设置为无需密码即可登录,否则您需要使用SSH输入密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM