Script to delete files older than 30days

Solution 1:

Assuming you really need to be using find in order to recurse through subdirectories:

find /export/home/ftp \( -name console.log -or -name server.log \) -mtime +30 -exec rm -f {} +

Solution 2:

If you just need to remove the old server.log and console.log every month you can also use logrotate which is most likely already running under RHEL. A config snippet like this will work in /etc/logrotate.d/*.conf or wherever the config files are located on your system.

# rotate server.log and console.log every month
# delete, not compress, old file

/export/home/ftp/server.log /export/home/ftp/console.log {
    monthly
    rotate 0
}

A custom monthly cron, as suggested above, will also work well. In fact, since logrotate is run from cron, you could consider this a cron extension of sorts. HTH.

Solution 3:

Why not just use a monthly cron?

@monthly /usr/bin/rm -f console.log @monthly /usr/bin/rm -f server.log

It would definitely be safer then doing things with find.