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 10 VPS machines and all of them have to run this one script that I need to change often, but I don't want to change it at 10 places, every time I need to make a change.

I put the script as a plain text file on a remote HTTP server. If I could wget this file and run the contents, that would be great.

But I'm not sure how to do it, or if there are alternative ways to achieve my goal?

share|improve this question
    
I had a similar situation that i have resolved by a more low-tech approach of using Dropbox and adding the execution to anacron. But if you have access to HTTP server then jordanm's approach will be the easiest for you. –  Volodya Jan 4 at 20:27
add comment

2 Answers

up vote 6 down vote accepted

As long as you understand the dangers, you can pipe the output to a shell:

wget -O - http://foo.com/somescript | sh
share|improve this answer
    
Can I put some variables in the remote file? basically: remote file has ./runxxx -id=$id and my local file has id=1 and then wget the remote file –  KoKo Jan 4 at 19:02
1  
@KoKo easiest thing to do would be to use an environment variable. –  jordanm Jan 4 at 19:21
add comment

You can do this in a push or pull way.

If you want to do it the pull way you can use wget or curl. From each host do:

wget -O- http://foo.com/somescript | bash

or

bash <(wget -O- http://foo.com/somescript)

However it might be easier to do it the push way. From a central host do:

for host in host1 host2 host3; do
  cat script.sh | ssh "$host" bash
done

Another option would be using puppet or chef. But depending on what you are doing that might be a bit overkill.

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.