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
Try running ssh user@remote sh ./script. unx . This only works if the script is in the default (home) directory on the remote.
Here, we force the communication protocol as SSH and give the script name under the option -m: C:\Users\baeldung. 01\Downloads>. \plink.exe -v -ssh [email protected] -m get_host_info.sh Looking up host "192.168.
ssh root@MachineB 'bash -s' < local_script.sh
I got it from that thread: How to use SSH to run a shell script on a remote machine?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With