A technology blog about Programming, Web Development, Tips, Tutorials, and Code Samples for developers.
3/05/2009
Untold Best Practices: Cleaning up the log file using cron script
Cleaning up the log files is a regular maintenance which may be required at a web server or a any other application. Below is a simple script which can be used to do automated clean up of files older then certain number of days. This example shows it for 30 days. You can change it as per your requirements.
cleanup.sh
#!/bin/sh
# Clean up the files older then 30 days
find /directory/to/cleanup -ctime +30 -exec rm -f {} \;
Add this cealnup.sh file call in your unix crontab daily jobs, so that it can clean up the files on daily basis. This is how the crontab entry should look like for running every midnight.
0 0 * * * /myscripts/cleanup.sh
Most of the times the logs files size causes disc space issue on web servers, and this way we can easily control the space availability.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Got something to say? Don't hold it! Tell it to us.