I transfer a file from a remote server to my local server. If this is done I do a diff to check if both files are identical to check if the transfer was successful. So I do this:
ssh -o StrictHostKeyChecking=no -l ${SSH_USER} ${SSH_HOST} "cat $FOLDERPATH_REMOTE.tar.gz" | diff - "$FOLDERPATH_LOCAL.tar.gz"
if [[ $? -eq 0 ]]; then
echo "\n##### Remove file from remote machine #####\n"
rm -f $FOLDERPATH_REMOTE.tar.gz
fi
When I do this, I get always an error like this:
diff: /home/backups/test.tar.gz: No such file or directory
and
[[: not found
But when I do a cat /home/backups/test.tar.gz
the file exists. So somehow the command does not distinguish between local and remote system and the if after the ssh command is not executing.
Does anybody knows what I am doing wrong?
P.S: And another beginner question: When do I have to write variables like this ${VAR}
and when like $VAR
?