简体   繁体   中英

Running a shell script to a remote linux server from the local window?

I am trying to run a shell script to execute a binary on a remote linux box. Both the binary and the shell script are on my local window machine. Is there any way through which i can run the binary to the remote machine directly from windows through command line tools like PLINK ?

I don't want to put the binary and the script to all the remote linux boxes which i want them to run on,Instead I want to run the shell script which will intern invoke the binary and do the desirable functions directly through my local machine.

You will have to copy the binary to the remote Linux box before it can be executed. However, you could have a script on the windows machine that uses sftp to transfer the binary program to a temporary directory under /tmp before running it, so there is no manual setup required.

You can run the shell script remotely, just by piping it through ssh:

cat my_script.sh | ssh -T my_server

(Or whatever the windows/plink equivalent is.)

However, you can't run the binary remotely through a pipe, the file will have to exist on the remote server. You can do this by pushing the file from your windows machine to a known location on the remote server, and then editing your script to expect the file to exist in that location:

scp my_binary my_server:/tmp
cat my_script.sh | ssh -T my_server

And then just have your script run that binary:

/tmp/my_binary

Or you can write the script so that it pulls the binary file from a central location where you're hosting it:

wget -O /tmp/my_binary http://my_fileserver/my_binary
/tmp/my_binary

Note, if the shell script doesn't do anything else besides invoke the binary, then you don't need it. You can just fire the commands directly through ssh:

ssh -T my_server "cd /tmp && wget http://my_fileserver/my_binary && ./my_binary"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM