SHELL SCRIPT TO CLEAN OLD TRACE OR LOG FILES AND SET CRONTAB IN LINUX

SHELL SCRIPT TO CLEAN OLD TRACE OR LOG FILES AND SET CRONTAB IN LINUX

Use the below command to housekeep the linux server where old trace files fill space often and cause distraction from critical tasks. ***Warning***, i have given a dot ‘.’ symbol in find command to detect all tracefiles in all mount points and remove them. If you are not sure what you do, then specify the absolute or relative path of log or tracefile directory ,test it manually and then schedule in crontab like this instead of using -name option

find /apps01/diag/rdbms/orcl19x/orcl19x/trace/*.trc -type f -mtime +1 -exec rm -rf {} \;

-bash-4.2$ crontab -e
find . -name *.trc -type f -mtime +3 -exec rm -rf {} \;

Below is the cronjob scheduled for every wednesday and saturday at 1AM to clean up the old trace files

-bash-4.2$ crontab -l
0 1 * * 3,6 find . -name *.trc -type f -mtime +3 -exec rm -rf {} \;

Leave a Reply

%d bloggers like this: