views:

436

answers:

3

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?

+2  A: 

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.

Steen
A: 

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.

gbjbaanb
+3  A: 

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.

Michael Aaron Safyan
Why not have the cron-job run on the target machine?
innaM
That's a very good question... I was in a similar situation where I had sufficient privileges on the server to run "svn update", but insufficient privileges to create my own cron jobs, and simply assumed that Tom was in a similar sitution. However, now that you bring it up, that is a silly assumption to make... it would definitely be better to run the cron job on the server computer.
Michael Aaron Safyan