how to execute a bash script on remote server while I am connecting to it

78 Views Asked by At

I am already connected to a remote server using ssh with running the following command

ssh user@ip

and connected to that server and I am in that server terminal now.

I want to execute a script exist on my loca machine on the remote server while I am connecting to it.

I know that there is another way to do that by doing something like this

ssh serverA "bash -s" -- < ./ex.bash

but my case is different, I want to execute the script after connecting to the server

how can I do that?

1

There are 1 best solutions below

0
keithpjolley On

Without a shared volume, like via NFS, you can't do it. If it's a simple script then you can scp /some/ex.bash remote:/tmp/ex.bash and then when you ssh to remote you can run /tmp/ex.bash.

Setting up NFS is more involved than an SO answer. See something like: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nfs-mount-on-ubuntu-20-04