I have a need where I must work with a set of files based on time elapsed (as I do not have control over when new files are added to the remote directory).
I must do several operations with this set of files, therefore I am attempting to store find
results in a variable (so I can be sure elapsed candidates don't change), then use the same list (without executing find
again) for each operation.
This is a stripped down version of what I'm attempting.
FILELIST=$(ssh ${SSHUSER}@${SSHHOST} "cd ${REMOTEPATH}; find -amin +${TIME} -type f,d -print")
if [[ ${#FILELIST} -lt 4 ]]; then
echo "No files" >> ${LOGFILE}
exit 1
fi
echo -en "Copying remote files to remote backup\n" >> ${LOGFILE}
ssh ${SSHUSER}@${SSHHOST} "cd ${REMOTEPATH}; cp -Rpv '${FILELIST}' ${REMOTEBACKUPPATH}" >> ${LOGFILE}
This of course gives me cp: missing destination file operand after ''
which I understand. I simply don't know how to get the file list formatted in a manner that cp
will like it.
I have worked on this a while, read documentation / SE posts, and cannot figure it out. I am hoping once I know what I'm doing wrong with cp
I can also apply that knowledge to rsync
.
I'm new to the bash scripting arena, if that is not not already clear. :)
Thanks in advance.
-exec
option offind
here? That would get rid of the intermediate step. – AdminBee Nov 18 '20 at 17:11find
call, then run each operation using that same list. – Spot Nov 18 '20 at 18:39ssh
. – Andrew Henle Nov 18 '20 at 20:37