Reputation: 121
find /Volumes/COMMON-LIC-PHOTO/STAGING/Completed -type d -maxdepth 2 -iname -iregex '.*_OUTPUT' -exec rsync -rtWv --stats --progress {} /Volumes/COMMON-LIC-PHOTO/ASPERA/ASPERA_STAGING/ \;
The code above is designed to look inside the directory Complete for any sub-directories with the phrase "_OUTPUT" (ignoring case, hence -iname
) at the end of the directory name and copy what it finds to a new location, Aspera_Staging. I'm running the code in a .sh triggered by the launchcd app Launch Control whenever a new directory is moved to Complete (which could be part of the issue because cron seems to be very picky).
It works about half the time, the other half it does nothing at all. An OUTPUT directory won't be copied. I can't find a pattern, it almost seems random. I've noticed in the debug log that it is giving me the following error:
find: .*_OUTPUT: unknown primary or operator
I've spent hours tinkering, trying to figure it out. I've followed a lot of suggestions found on here and other sites but so far nothing has worked. It obviously has something to do with it looking for the Output folders but I just can't get to the bottom of it.
Upvotes: 2
Views: 17057
Reputation: 6144
As commenters have noticed, -iname
requires a parameter, therefore the -iregex
that follows is understood as that parameter and the parameter to -iregex
is (mis)taken as an operator, hence your error message.
In your context, -iname
and -iregex
seem redundant, so your command should be either:
find /Volumes/COMMON-LIC-PHOTO/STAGING/Completed -type d -maxdepth 2 -iname '*_OUTPUT' -exec ... \;
or:
find /Volumes/COMMON-LIC-PHOTO/STAGING/Completed -type d -maxdepth 2 -iregex '.*_OUTPUT' -exec ... \;
(notice how the parameters to -iname
and to -iregex
slightly differ)
Upvotes: 1