Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I run a script locally from a remote server such as www.mysite.com/script.sh

I tried:

. www.mysite.com/script.sh

and it does not work.

share|improve this question

migrated from serverfault.com Aug 10 '13 at 8:18

This question came from our site for professional system and network administrators.

2  
Why on earth would you want to do that? The website may just change that script to read "rm -rf *" or worse. –  Grant Aug 9 '13 at 18:23
    
@Grant Because I can store a bunch of scripts on my web server and have access to them anywhere whenever I need them without having to download them or carry them around on a USB stick. –  RecoJohnson Aug 9 '13 at 18:25
    
You have to download them. That's what getting the data from the server is. –  Etan Reisner Aug 9 '13 at 18:34
add comment

2 Answers 2

up vote 3 down vote accepted

If you wrote the script -- meaning that you're absolutely certain you know what it does -- you can just do this:

curl -s http://www.mysite.com/script.sh | sh

That uses curl to fetch the script and pipe it to the Bourne shell. But in general, for anything you didn't actually write yourself, you should do what Grant suggested and read it first, because this is a great way to accidentally run malicious code.

So while this does, of course, "download" the script, it simply sends the data through the pipe rather than saving it to a file.

share|improve this answer
add comment
wget http://www.whatever.com/script.sh

Then read the script to ensure it doesn't do anything malicious.

Then chmod +x script.sh and ./script.sh

share|improve this answer
    
Or just sh script.sh without bothering with permissions. –  larsks Aug 9 '13 at 18:39
    
Yes assuming they are all sh scripts. Some could require other interpreters. –  Grant Aug 9 '13 at 18:53
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.