Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am writing a shell script to run a mysql backup as a cron job and am hitting an issue with the find command not being supported in the rackspace cloud sites cron environment. Any attempt to use the find command gives: /usr/bin/find: Permission denied

What alternatives are there to doing:

find *.gz -mtime +7 -delete

when the files are named like this :

gzip > /mnt/target03/rest-of-path/web/backups/DATABASENAME_`date "+%Y-%m-%d"`.gz

?

I was hoping that I could parse the file's date without using find in a loop, something like:

FILES=./path/to/files/*
for f in $FILES
do
 #delete files older than 7 days without using find

done
share|improve this question
    
Can you explain what you mean about it not being supported? Is it not installed? –  Jeff Ferland Dec 20 '11 at 16:53
2  
Try, /usr/bin/find path -name '*.gz' -mtime +7 -delete. Try setting your PATH in the script or using the full path. –  Zoredache Dec 20 '11 at 16:59
    
Is that a RedHat system? If not, which distro? –  Tim Dec 20 '11 at 18:14
    
By not supported I mean that the the cron user does not have permission to use the find command. I have updated the question. –  codecowboy Dec 21 '11 at 9:20
    
Cloud sites is built on RedHat Enterprise server –  codecowboy Dec 21 '11 at 9:28

2 Answers 2

I would suggest uploading your own copy of find if it doesn't exist there.

If that doesn't work, a Perl script using the File::Find module might be useful.

share|improve this answer
    
I will have to do it in PHP as I don't know perl but I'm guessing some kind of directory iteration and deletion is probably what I will end up doing. –  codecowboy Dec 21 '11 at 9:29

This could be a PATH environment issue. As a commenter mentioned, you may want to try the full path in your cron.

Try

whereis find
which find
locate find

To see if you can identify the full path to find.

On Red Hat systems, find is part of the findutils RPM and typically located at:

/usr/bin/find

so rewrite your cron as:

/usr/bin/find *.gz -mtime +7 -delete
share|improve this answer
    
I have been told by rackspace that I simply will not have permission to run the find command. I have updated my question with the relevant error. –  codecowboy Dec 21 '11 at 9:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.