I am new to shell scripting. I want to clear log files in a directory based on the dates. I have managed to gather this code:
DIR1='/home/u01/app/oracle/servers/DIR1/logs' DIR2='home/u01/app/oracle/servers/DIR2/logs' DIR3='home/u01/app/oracle/servers/DIR3/logs' Admin='/home/u01/app/oracle/fmw/admin_poc001/domain/domain_IAM_POC01/servers/AdminServer/logs' echo "Enter the path" read path if [ $path == $DIR1 || $path == $DIR2 || $path == DIR3 || $path == $Admin ] then echo $path "check your path" find $path -mtime +10 --# This line here "10" represents listing out the last 10 days logs for i in *.log* *.out* do cat /dev/null >"$i" done else echo "Re-enter the Correct path" read path fi
This script gives me output when I give input like this:
Enter your path : /home/u01/app/oracle/servers/DIR1/logs
It will clear all the log files until the date of running that script.
But I want that if I run this script I can clear the log files for times other than the last 10 days, i.e., if I run this today (24/06/2015), then I can clear the log files before the date 14/06/2015.
Also: rather than entering the full directory path, can I store that in a variable and just type that variable name (instead of entering the full directory path)?
For example, instead of entering
/home/u01/app/oracle/servers/DIR1/logs I am looking for a procedure where I can just enter DIR1 so that it can go into that directory without the total path.