I'm trying to copy files from remote server this way:
transferFiles() {
for FILE in `ssh $USERNAME@$HOSTNAME find "${DIR}" -type f -mtime -1 -name "*log*" 2>/dev/null` ; do
rsync -zR $USERNAME@$HOSTNAME:$FILE "${DIRII}"
done
}
I want to copy all files which contains 'log'.
Unfortunately something is not working, I suspect that problem is quotes, I tried many solutions but still nothing.
Sorry I wasn't enough detailed.
I was trying to echo $FILE
inside loop to check if something is being sent to this variable. echo shows nothing, that's why I'm assuming that problem is in first line.
Additionally I was trying to execute directly
ssh $USERNAME@$HOSTNAME find "${DIR}" -type f -mtime -1 -name "*log*"| less
but output was empty. In this case solution was insert find inside single quote
ssh $USERNAME@$HOSTNAME 'find "${DIR}" -type f -mtime -1 -name "*log*"'| less
This one is working. But now my problem is how to apply this into script. I can't do something like this:
transferFiles() {
for FILE in `ssh $USERNAME@$HOSTNAME 'find "${DIR}" -type f -mtime -1 -name "*log*"' 2>/dev/null` ; do
rsync -zR $USERNAME@$HOSTNAME:$FILE "${DIRII}"
done
}
I tried also double quote except single quote for ssh and for find.
alternately quote " ' ' "
also not resolving this issue.
echo
to just see what would have been executed.rsync --files-from=-
. Or you could also run the rsync on the remote back to this machine, provided you have setup the usual ssh keys in that direction (you would need to quote the pipe|
to ensure it was passed to the remote shell).