-->

Automating svn update

2020-07-14 10:27发布

问题:

I'm frequently sshing into a server, switching to a specific directory and running svn-update

I'm thinking that there's probably a very easy way to automate this, so I can simple specific a subdirectory when I run the script and it'll login via SSH, cd to the right directory and run svn-update.

Is this a job for capistrano or could a simple bash script do the job?

回答1:

Sounds like a job for cron. Execute crontab, and add an entry like so:

#min hour date month day command
 0   *    *    *     *   ssh user@host '(cd path/to/working/copy; svn update)' 

You may need to set up ssh passwordless authentication with ssh-agent so that it won't prompt.

EDIT (per comments below):

Assuming you have sufficient privileges to do so, run

ssh user@host crontab -e

Then add an entry like so:

#min hour date month day command
 0   *    *    *     *   (cd path/to/working/copy; svn update)

You can ignore the part above the edit, unless your server doesn't allow you to use cron.



回答2:

Perhaps you should ask yourself why you are performing this action?

Could a build server such as CruiseControl or Hudson solve the more general case (of knowing when a svn commit has been performed)?

If you need monitoring on a specific svn server, and you have administration access to it, you can enable a post-commit hook to the server, for instance to send you an email on every commit (or only on some specific types of commits).

It would help, if you could clarify the usecase of your situation.



回答3:

simple bash script will do it, add the svn update command to your /etc/profile file.

See here for bash login script processing.

If you want to run it from a different box (ie not log in) just remember than ssh will not exit if there is a running process, so you may want to run the update in the background, with all out redirected to /dev/null.