1

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
codecowboy
  • 1,307
  • 7
  • 18
  • 31

2 Answers2

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.

Jeff Ferland
  • 20,547
  • 2
  • 62
  • 85
  • 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 09:29
0

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
jeffatrackaid
  • 4,142
  • 19
  • 22
  • 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 09:25