How do I execute a script on another server using

2019-06-14 01:45发布

问题:

Consider I have two servers A and B.
And on the server B, I have a script test.sh.

I want to execute this test.sh from server A using FTP connection between them and also I want to pass a variable to the script of B but the variable is defined at A.

OR

If I SSH to server B from A, just after ssh command , i will execute the shell script at B. But if i want to add a variable (that i have defined while i was at A) as an argument to script of B. how would i do it ? any suggestion ?

Please suggest.

Thanks in advance.

回答1:

Without seeing your code is difficult to see what you are trying to do exactly, but if you use double quotes your variable should be interpolated before send the value of it to the remote host, ex:

ssh user@127.0.0.1 "~/bin/script.sh $Local_Variable"


回答2:

Some, but not many, FTP servers support SITE EXEC command.

In the common *nix ftp client, you can use quote command to execute the SITE FTP command:

quote SITE EXEC test.sh param1 param2

But this will probably not work with your server. In most cases, you won't be able to execute a shell command over FTP.

Though if you have an SSH/shell access, use the ssh to execute the script.