I am trying to move files on a remote machine from folder A to folder B via ssh.

I am using this command: ssh user@server "sh scan/script.sh"

This will run a script which contains some file operations, moving files around on the remove machine. The problem is that my SSH seems to attempt to execute the contents of script.sh on my local computer.

I am using zsh.

Thanks for the help

  • Pass the -v flag to ssh to understand what is happenning – Basile Starynkevitch Jan 22 '12 at 7:17
  • "The problem is that my SSH seems to attempt to execute the contents of script.sh on my local computer." Is it moving the files on the remote machine? Is it moving the files on the local computer? Why do you suspect the script is being executed on the wrong computer? – dave4420 Jan 22 '12 at 10:12

You can execute remote commands through ssh, for instance:

ssh -n user@host mv fileOnRemoteServer destination

| improve this answer | |

You're on a Linux box? That should work without any problems.

Now, are you sure that the command isn't running on the remote machine, but merely displaying the output of the script on your machine? That would make it appear the script is running on your machine even though it isn't.

| improve this answer | |
  • This was the case. Thanks! Is there any way this can be avoided? – Hendrik Jan 22 '12 at 13:55
  • @Hendrik - When you log in with SSH, some systems set an environment variable of SSH_CLIENT or SSH_CONNECTION. I'm Kornshell, not BASH, so I can't verify this, but might be possible to set something up in .bashrc to print a warning if one of these environment variables are set. Doesn't work in Ksh because you set the name of the environment file in .profile and ssh doesn't execute that. Give it a try and let me know. Otherwise, you'll have to put something in your scripts itself. – David W. Jan 22 '12 at 21:24

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.