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?

  • 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. – v010dya Jan 4 '14 at 20:27

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

wget -O - http://foo.com/somescript | sh
| 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 '14 at 19:02
  • 1
    @KoKo easiest thing to do would be to use an environment variable. – jordanm Jan 4 '14 at 19:21

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


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

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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