Say I have the following Bash script stored in the file foo.sh
:
#!/bin/bash
echo foo
Without having to scp
the file, how could I execute the script stored in foo.sh
on a remote machine?
I have tried the following (with a few variations) to no success:
$ ssh root@remote eval `cat foo.sh`
eval `cat foo.sh`
seems to expand to eval #!/bin/bash echo foo
here
Now tested, though: handle with care! :)
(removed dash (see comments) and nearly everything :) )
In accepted answer I see:
That should be it:
or better, with a here-in document
I got it from that thread: How to use SSH to run a shell script on a remote machine?
cat foo.sh | ssh -T root@remote
will to the trick. The-T
option suppresses a warning you would otherwise get because you're piping input from a file.