Mule Application Logs Auto Cleanup using Crontab
Crontab:
you can automate process like backup, schedule updates and synchronization of files and many more. Cron is a daemon to run schedule tasks. Cron wakes up every minute and checks schedule tasks in crontable. Crontab (CRON Table) is a table where we can schedule such kind of repeated tasks.
Advantages of a cron job:
· You more easily have control over when it runs. You control the minute, hour, day, etc, that it will execute.
· It's easier to write the code and to manage its operation. It eliminates the looping and timing logic in the task, and you run crontab to change the timing or shut it off.
· It's not occupying memory in your system when it's not running.
· If it fails and exits for some reason, it will start up again when the proper time comes.
Disadvantages:
1. Smallest resolution is 1 minute:
If a task needs to run every 30 seconds, you can’t do it with cron.
2. Error handling:
If a job fails, what should happen? Solutions have been built to solve this single problem. Developers love adding more band-aids rather than admitting there is a better way.
3. Logging:
Crons don’t log, unless you tell them too. It is rare to see people log output of their cron jobs.
crontab configuration file will be available under /etc/crontab
cat /etc/crontab
Before we have to run this crontab first create one shell script file for mule logs clean and after a creates tar file.
In my case we are created the mule-logs.sh script file, in this script file declaring the Mule home as a variable and defining mule-standalone path and creating the tar file with filename as a timestamp.tar.gz from /data1/mule/mule-standalone-3.9.0/logs/*.log all logs files in this location after created tar files this logs will removed.
Now configured crontab under /etc/crontab.
vi /etc/crontab
After configured crontab now start the service using below command.
service crond start
Here we are configured every 2minutes that shell script will be executed with user is root. Every 2 minutes tar files are generated.