I’m trying to automate a script that copies a file from my local server to a remote server on the command line. I’ve done the research on scp and know how to copy the file to the remote server, but then I want to append that file to another.
This is my code:
scp ~/file.txt user@host:
ssh user@host cat file.txt >> other_file.txt
When I enter everything into the command line manually as such, everything works fine:
scp ~/file.txt user@host:
ssh user@host
cat file.txt >> other_file.txt
But when I run the script, only the file is copied, not appended to the end of other_file.txt. Help?
The second line of your code should be
Three important points:
>>in any way (which it does if it’s unquoted)>>in the command correctly.sshare “joined” to form a command, not carried into anargvarray as they are. It may be convenient but it also may lead to confusion or bugs:ssh cat "$MYFILE"andssh "cat '$MYFILE'"both work in a common use case, but they both break for different values of$MYFILE.