I have the following script in my /etc/cron.d:
19 15 * * * root /opt/scripts/clean-nexus-release-repo.sh
The clean-nexus-release-repo.sh script looks like this:
#!/bin/bash
find /opt/sonatype-work/nexus/storage/releases/se/company* -regextype posix-extended -depth -regex '.*/r?[0-9]{5,7}[a-Z0-9_.-]*\.[0-9]{1,3}' -mtime +60 -type d -print -exec rm -r {} \;
find /opt/sonatype-work/nexus/storage/releases/nu/company -regextype posix-extended -depth -regex '.*/r?[0-9]{5,7}[a-Z0-9_.-]*\.[0-9]{1,3}' -mtime +60 -type d -print -exec rm -r {} \;
When I run the clean-nexus-release-repo.sh script from my shell everything works fine. When it is run through cron I get the following output:
find: Invalid range end
find: Invalid range end
This is the same error I get when I move the hyphen in the [a-Z0-9_.-]
regular expression to an invalid position. I have tried the following but I still get the same error:
- Specifying an absolute path to the find command
- Escaping the hyphen with a backslash
- Removing that hyphen
find --version
gives:
find (GNU findutils) 4.4.2
Running on Linux devtools01 2.6.32-71.el6.x86_64 (CentOS Linux release 6.0)
Best Answer
I'm not sure I can give the perfect technical explanation here. maybe someone else can improve the answer.
basically I remember range expressions being locale dependent, so [a-Z] does not necessarily mean the same thing as [a-zA-Z]
I think the relevant documentation is:
http://www.gnu.org/software/grep/manual/grep.html#index-range-expression-216: