UNIX ssh script, running commands on a remote server

I would like to create a script that automatically logs in to the remote server and captures the file on the server. The script is already registered on the server, however, the commands do not run on this computer. As soon as I disconnect from the remote server, the commands run on the client machine.

!/bin/sh
ssh -o PreferredAuthentications=publickey brjones@server.com
cd ~/folder
"i would like to grab file and copy it to client machines folder"

EDIT: I'm not sure what you noticed, but I am using a passwordless connection to a remote server using ssh and keygeneration. I appreciate the ideas, but I'm looking for maybe commands on the pipe or run commands on a remote server using a script on the client. I understand that the remote server does not have access to the client script, however, I was curious whether it is possible to transmit commands through an ssh connection.

+5
source share
10 answers

You should use scp ("safe copy") and not ssh ("secure shell").

+14
source

Also, if you do not want to have a script available on the remote server, try the following:

ssh thehost 'cd /tmp; ls; echo Hello world, I am `hostname`'

and for copying without SCP:

ssh localhost 'cat /bin/bash' > local_bash
+13
source

, scp. script stdin :

!/bin/sh
ssh -o PreferredAuthentications=publickey brjones@server.com << EOT
cd ~/folder
echo "hello" > hello.txt
...
EOT
+5

ssh , ,

ssh user@server exec /path/to/script/script.sh

script.sh user.


script , ( NFS ), script scp :

scp script.sh user@server:/path/to/script/

, , ,

scp user@server:/path/to/file/filename .

.

+3

ssh script . , ssh, :

ssh brjones@server.com do_foo.sh

do_foo.sh script

, SCP.

+2

Tiemen, , script :

ssh thehost < commands.sh
+2

? Remote - . script ssh . ...

Yarek T:

, , script .

+1
0
source

Several people have already explained how to make a concrete example that you give better and easier.

If you really need a remote interaction script, you can use expect.

0
source

If you want to call a script on a remote host that is present on localhost

ssh remote Password@remoteHostname < localScript.sh

If you want to call a script that is already on a remote host

ssh remote Password@remoteHostname "$PATH_OF_SCRIPT/remoteScript.sh"

0
source

All Articles