Score:2

copying a directory from one location to another in the same server but the script to copy is present in another server

pl flag

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.

CrazyTux avatar
us flag
"same directory but different location" - is it another sub directory in the same server or the same directory on another server ?
pa4080 avatar
cn flag
Instead of `scp` you can use the `ssh` command in this way: `ssh user@host 'cp -R /dest/dir /target/dir`'
Aman Srivastava avatar
pl flag
another sub directory in the same server
vanadium avatar
cn flag
Show us what you tried thus far: that may render your specific problem more clearly. With `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.
CrazyTux avatar
us flag
check out this guide https://www.shellhacks.com/ssh-execute-remote-command-script-linux/
Aman Srivastava avatar
pl flag
The solution shared by @pa4080 worked for me, thanks for all the help
Score:4
cn flag

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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.