开发者

SVN Update Crontab Linux

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 in开发者_StackOverflowcorrectly 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.


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜