-1

I am running ssh command and doing move command in it.

ssh $USER_ID@$DESTINATION_SERVER "mv /source /destination"

This is working fine. But I have to do this with multiple files in many source and destination directories. If I repeat the command then it will ask for password everytime. Please help.

  • separate your commands using ; ? ex: cmd1 ; cmd2 ; cmd3 .. but perhaps there is a better way – Sundeep Jul 19 '16 at 9:01
  • 2
    Use SSH keys (and agent) so you don't need to repeat the password each time. Or just log in and run all the commands from a remote shell (which would give you tab-completion too) – ilkkachu Jul 19 '16 at 9:24
0

Separating the command using ; worked.

ssh $USER_ID@$DESTINATION_SERVER "mv /source1/* /destination1/; mv /source2/ /destination2/; ......"
  • if you don't need to use any local variables (or command substitution etc) in that ssh command, use single-quotes rather than double. BTW, another method is to write a script to do what you want, scp it to the remote system (e.g. scp myscript user@remote:/tmp and execute it with ssh, e.g. ssh user@remote bash /tmp/myscript. Finally, use key-based authentication rather than a password. basic setup is as easy as running 'ssh-keygen` followed by ssh-copy-id user@remotehost. – cas Jul 19 '16 at 14:33

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.