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

link|improve this question
Pass the -v flag to ssh to understand what is happenning – Basile Starynkevitch Jan 22 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 at 10:12
feedback

migrated from stackoverflow.com Jan 22 at 9:53

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 1 down vote accepted

You can execute remote commands through ssh, for instance:

ssh -n user@host mv fileOnRemoteServer destination

link|improve this answer
Thank you I accepted this answer now. Works perfect. – Hendrik Feb 4 at 10:59
feedback

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.

link|improve this answer
This was the case. Thanks! Is there any way this can be avoided? – Hendrik Jan 22 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 at 21:24
feedback

Your Answer

 
or
required, but never shown

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