I am trying to write a script in a server which copies a directory present in another server and paste it in the same directory but at different location, what is the correct format for the SCP command for this process.
1 Answer
To complete the task, you can use the ssh
command in a way as this:
ssh user@host 'cp -R /source/dir /dest/dir'
Thus instead of opening a login shell the ssh
client will execute the command within the quote marks on the remote system and then will close the connection. In this case the remote system will process the data.
In addition you can capture the output of the command and save it as a local file if you need, for example:
ssh user@host '<remote command>' > /local/path/file.log
ssh user@host '<remote command> 2>&1' > /path/file.log # capture the remote errors
scp
you can use thessh
command in this way:ssh user@host 'cp -R /dest/dir /target/dir
'scp
, you can specify source and destination on remote hosts, so I do not see your specific problem as long as you specify correct pathnames to the remote host.