You have already known about the tradition but more effective log archiving script, if you don’t then you might want to check this script first.
In case if you have many different jobs running and they are creating huge files under its individual directory then let’s modify little bit our script so we can use the same script for all the jobs instead of creating multiple script
This is very easy way of reusing your script just by-passing parameter outside from the script. We need to provide the parameter(s) while running the script.
In our example, lets consider we have multiple directories under /local/apps/BatchServer/
You can make this script very generic by passing “directory name”. Assume, you have sub-directories like – MyDIStudioJob_1, MyDIStudioJob_2, MyDIStudioJob_3, etc. You can pass these directory name from outside and it is referred and replaced by $1 in the script.
Now your LEVROOT will become – LEVROOT=/local/apps/BatchServer/$1
PS- Make sure you have Log and Archive folders created under each sub-directory.
LOG ARCHIVING SCRIPT
Let’s say you want to run this script for job number 1 which has logs generated under subdirectory MyDIStudioJob_1
Or may be you want to run for Job number 3 as –
PS: This script is all about moving the long files into Archive and clean up there. But if you have job or application running 24/7 then you can’t move your log files from original directory. You may want to check this best possible solution here in another blog post to handle such scenarios.