9 Crontab and DBM - Schedular
9 Crontab and DBM - Schedular
Ltd
Performans Tuning
Create a job
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'my_java_job',
job_type => 'EXECUTABLE',
job_action => '/usr/bin/java myClass',
repeat_interval => 'FREQ=MINUTELY',
enabled => TRUE
);
END;
/
Remove a job
EXEC DBMS_SCHEDULER.DROP_JOB('my_java_job');
EXEC dbms_scheduler.run_job('myjob');
Examples:
BEGIN
DBMS_SCHEDULER.ENABLE('myjob');
Futurematics.Pvt.Ltd
Performans Tuning
END;
BEGIN
DBMS_SCHEDULER.DISABLE('myjob');
END;
Monitoring jobs
Use user_scheduler_jobs and user_scheduler_job_log to only see jobs that belong to your user (current schema).
Crontab
This line executes the "ping" command every minute of every hour of every day of every month.
The standard output is redirected to dev null so we will get no e-mail but will allow the standard
error to be sent as a e-mail. If you want no e-mail ever change the command line to "/sbin/ping -c
1 192.168.0.1 > /dev/null 2>&1".
This line executes the "ping" and the "ls" command every 12am and 12pm on the 1st day of
every 2nd month. It also puts the output of the commands into the log file /var/log/cronrun.
This line executes the disk usage command to get the directory sizes every 2am on the 1st
through the 10th of each month. E-mail is sent to the email addresses specified with the
MAILTO line. The PATH is also set to something different.
PATH=/usr/local/sbin:/usr/local/bin:/home/user1/bin
MAILTO=user1@nowhere.org,user2@somewhere.org
0 2 1-10 * * du -h --max-depth=1 /
Futurematics.Pvt.Ltd
Performans Tuning
This line is and example of running a cron job every month at 4am on Mondays, and on the days
between 15-21. This is because using the day of month and day of week fields with restrictions
(no *) makes this an "or" condition not an "and" condition. Both will be executed.
0 4 15-21 * 1 /command
Run on every second Sunday of every month. The test has to be run first because of the issue
mentioned in the example above.
Instead of the first five fields, one of eight special strings may appear:
string meaning
------ -------
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".