Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com Jan 22 '12 at 9:53

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

    
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

2 Answers 2

up vote 2 down vote accepted

You can execute remote commands through ssh, for instance:

ssh -n user@host mv fileOnRemoteServer destination

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

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.

share|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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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