AIX Create Task Scheduler using Crontab

Problem : I want to run a scheduled bash script every day at 00: 00

Example : For backup of tomcat log file so everyday it will rename previous day catalina.out to catalina.out.[YYYYMMDD] and write today log to catalina.out

Condition :

– OS running IBM AIX 6.0

– logrotate installed.

Solution :

Create your bash script (ex : tomcat_log.sh) :

#!/bin/sh

logrotate /home/danielniko/tomcat_logrotate -s /home/danielniko/rotate.status

Check existing cron jobs (in my case, I already add the job)

$ crontab -l

0 0 * * * /oss/cron/tomcat_log.sh

To remove the entry in crontab list, use the following. Command “sed” delete the line with text containing tomcat_log.sh

$ crontab -l | sed '\!tomcat_log.sh!d' | crontab 

$ crontab -l

Executing crontab –l again will show that our previous job already deleted.

Now lets add the job again.

$ crontab -l | awk '{print} END {print "0 0 * * * /oss/cron/tomcat_log.sh"}' | crontab

$ crontab -l
0 0 * * * /home/danielniko/open.sh

 

Explanation :

We are creating a job that runs every 0 minute at every 0 hour every day. The * symbols means every.

So each fields has the following meanings:

# field #   meaning        allowed values
# -------   ------------   --------------
#    1      minute         0-59, *
#    2      hour           0-23, *
#    3      day of month   1-31, *
#    4      month          1-12, * (or names)
#    5      day of week    0-7, * (0 or 7 is Sun, or use names)