Allow me to tell a very short story. It involves a program that we computer operators (that should tell you how old I am) used to run on an IBM 1401 at the University of California at Irvine. It was a 36-hour run. It would print six copies of each student's class schedule on cardboard stock. It would also make nonrepeatable changes on disk, so you couldn't rerun the program if you fouled things up with the printer (easier done than said, even). You'd have to call in the programmer, who was a grouchy sort with a foul tongue and much political power. So you did whatever you had to, to make sure you didn't call him.
As luck would have it, I messed up on the printer. I don't want to tell you what I had to do to avoid calling him. I will tell you that it involved marking the bad place in the printed output, running something unauthorized at the end, and spending the intermediate hours writing a tiny machine (not assembly) language program, desk checking it several times thoroughly, and manually multi-punching it so it would be ready to run at the end.
And I learned a lesson: if the output is important, break up the task into two or more phases if possible.
So,
wildside, my advice to you is this: first generate the list of files to copy, and then copy them. To do that, make these changes to your script:
Code:
#!/bin/bash
echo #!/bin/bash > copyscript.sh
find /FolderA -type f | while read f
do
destfile=$(echo "$f" | sed 's#/FolderA#/FolderB#')
if find "$destfile" -newer "$f"
then
echo echo "$destfile is newer than $f, skipping" >> copyscript.sh
else
echo echo cp -p "$f" "$destfile" >> copyscript.sh
echo cp -p \"$f\" \"$destfile\" >> copyscript.sh
fi
done
chmod 700 copyscript.sh Then run your first script. Then casually examine your second script, which will contain every copy command, plus echo commands for all files.
When you're satisfied, then run the second script.