I would like to create a script that automatically logs into a remote server and grabs a file on the server. The script already logs into the server however the commands are not run on that machine. Once I disconnect from the remote server, the commands are run on the client machine.
!/bin/sh ssh -o PreferredAuthentications=publickey email@example.com cd ~/folder "i would like to grab file and copy it to client machines folder"
EDIT: I am not sure if you noticed but I am used a passwordless connection to the remote server using ssh and keygeneration. I appreciate the ideas but I am looking to possibly pipe commands or run commands on the remote server with the script on the client. I realize that the remote server does not have access to the client script, however I was curious if it was possible to pipe the commands through the ssh connection.
你应该使用scp（“secure copy”）而不是ssh（“secure shell”）。
Also, if you don't 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 SCP-less copying:
ssh localhost 'cat /bin/bash' > local_bash
If your goal is only to transfer files, you should use scp. But to execute some commands on the remote host without having a specific script on that remote host, you can simply use the stdin like this:
!/bin/sh ssh -o PreferredAuthentications=publickey firstname.lastname@example.org << EOT cd ~/folder echo "hello" > hello.txt ... EOT