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@
root@'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).


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@ "bash -s" -- < ./my_local_script "Arg1" "Arg2"

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.