Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have gitolite on a Centos 5.5 box - when a repository is updated, I need to send a command to my bug tracking appliance to get the new commands. Right now, I have the following command working:

ssh bugserver -f 'cd /etc/repos/gitrepo && git pull origin prod && exit'

This seems a little dirty, though. Is there a better way to execute this sync?

share|improve this question
3  
Why do you find this dirty? You can omit the redundant && exit at the end, but after that, what do you hope to do better? –  Gilles Oct 12 '11 at 23:29
    
I wasn't really sure if this was the correct way to do it, but judging by the responses, it looks like it is the least complicated method. Also, why can I omit the && exit? Wouldn't it keep the SSH session open? –  Nic Oct 14 '11 at 18:30
    
When ssh is used to pass commands, it automatically closes the client session when the commands complete. –  bgvaughan Oct 16 '11 at 1:52
add comment

4 Answers

Put it in a Makefile.

sync:
↹ssh bugserver -f 'cd /etc/repos/gitrepo && git pull origin prod && exit'

Then run it.

$ make sync

Note that is actually a tab character. See your editor's documentation for how to enter it (but CtrlVTab may work).

share|improve this answer
add comment

You may be able to script something up using Expect, but that may be over complicated for something this simple. I've used it in the past to login to a remote power switch and cycle a given port, so I believe you could probably use it for this application as well.

share|improve this answer
    
you can use expect to do anything that requires repeatable, consistent, interaction. –  Tim Kennedy Oct 12 '11 at 14:53
    
Very true. I was just thinking that this may be easier to use a bash alias or something simple like that. I am a big fan of expect now though; made my life much easier. –  sbtkd85 Oct 12 '11 at 15:10
add comment

Here are two additional solutions, both assume you are using bash shell. The first is to create a function to perform the task, place that function in your ~/.bashrc file:

function bugsync() {
    ssh bugserver -f 'cd /etc/repos/gitrepo && git pull origin prod'
}

The second is to create an alias:

alias bugsync="ssh bugserver -f 'cd /etc/repos/gitrepo && git pull origin prod'"

Note that you don't need to specify the '&& exit' part of the command.

share|improve this answer
add comment
up vote 0 down vote accepted

After considering the options, I decided to modify the command (removed the && exit) and left it as is for simplicity.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.