4

I am trying to figure out how I could manage more easily my servers. I'd like to know if I can make my scripts available to all the servers without copying them to the servers.

They are located in my computer (client side),

bash-3.2$ ls -l my_local_script
-rwxr--r--  1 mario  staff  554 Jan  9 13:35 my_local_script

I always login remotely with my terminal using SSH

bash-3.2$ ssh root@192.168.56.140
root@192.168.56.140's password:
[root@prodsrvr00 ~]#

Once I am logged into the server, I'd like to know if there is any way to execute the script like it was locally available without copying it to the server.

[root@prodsrvr00 ~]# my_local_script

Since it's a NAT network, I cannot SSH back to my computer (the client).

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

5

To do it after logging into the remote server, do:

ssh <local_machine_where_script_resides> "cat <Full_path_to_my_local_script>" | bash

replace "bash" with whatever interpreter is required by your script (I wouldn't recommend this way and prefer below)

There is a way to do this without logging into remote machine:

ssh <remote_machine> "bash -s" -- < ./my_local_script "Arg1" "Arg2"

In your case, it is:

ssh root@192.168.56.140 "bash -s" -- < ./my_local_script "Arg1" "Arg2"

I would suggest as well to look into options like puppet, chef, ansible etc.,.

VanagaS
  • 774