If Machine A is a Windows box, you can use Plink (part of PuTTY) with the -m parameter, and it will execute the local script on the remote server.
plink root@MachineB -m local_script.sh
If Machine A is a Unix-based system, you can use:
ssh root@MachineB 'bash -s' < local_script.sh
You shouldn't have to copy the script to the remote server to run it.
If you are trying to just test the functionality of your JavaScript file: create a blank HTML file, add a link to your JS file as you would normally load a JS file from HTML, and open the HTML file in Chrome. Go to the JavaScript console. You'll be able to interact with the functionality of your JS code as usual. You wouldn't need to set up a server for this. If still not clear, here's an example:
<html>
<head>
<script type = "text/javascript" src = "path/to/your/jsfile"></script>
</head>
</html>
<script src = "/js/file.js"></script>
load file.js on your local server
<script src = "http://example.com/js/file.js"></script>
load file.js on internet at http://example.com
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 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.curl
So while this does, of course, "download" the script, it simply sends the data through the pipe rather than saving it to a file.
You'll need to download the content of the script in some way. You could do
ssh remote-host cat script.bash | bash
But that would have the same kind of problem as:
cat script.bash | bash
namely that stdin within the script would be the script itself (which could be an issue if commands within the script need to get some input from the user).
Then, a better alternative (but you'd need a shell with support for process substitution like ksh, zsh or bash) would be:
bash <(ssh remote-host cat script.bash)
Both approaches do download the script in that they retrieve its content, but they don't store it locally. Instead the content is fed to a pipe whose other end is read and interpreted by .bash
You can also have the content of the remote script executed in the current bash process with:
eval "$(ssh remote-host cat script.bash)"
But that downloads the script fully (and stores it in memory) before running it.
The obvious solution would be to do:
. <(ssh remote-host cat script.bash)
But beware that some versions of bash have issues with that.