0% found this document useful (0 votes)
14 views3 pages

9 Crontab and DBM - Schedular

Uploaded by

shraddhadhok13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

9 Crontab and DBM - Schedular

Uploaded by

shraddhadhok13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Futurematics.Pvt.

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');

Run a job now

To force immediate job execution:

EXEC dbms_scheduler.run_job('myjob');

Change job attributes

Examples:

EXEC DBMS_SCHEDULER.SET_ATTRIBUTE('WEEKNIGHT_WINDOW', 'duration', '+000


06:00:00');
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE
('WEEKNIGHT_WINDOW', 'repeat_interval',
'freq=daily;byday=MON, TUE, WED, THU,
FRI;byhour=0;byminute=0;bysecond=0');
END;

Enable / Disable a job

BEGIN
DBMS_SCHEDULER.ENABLE('myjob');
Futurematics.Pvt.Ltd
Performans Tuning

END;
BEGIN
DBMS_SCHEDULER.DISABLE('myjob');
END;

Monitoring jobs

SELECT * FROM dba_scheduler_jobs WHERE job_name = 'MY_JAVA_JOB';


SELECT * FROM dba_scheduler_job_log WHERE job_name = 'MY_JAVA_JOB';

or checking from JOB owner schema

SELECT * FROM user_scheduler_jobs WHERE job_name = 'MY_JAVA_JOB';


SELECT * FROM user_scheduler_job_log WHERE job_name = 'MY_JAVA_JOB';

Use user_scheduler_jobs and user_scheduler_job_log to only see jobs that belong to your user (current schema).

Crontab

Use the command "crontab -e" to edit your crontab file.

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".

* * * * * /sbin/ping -c 1 192.168.0.1 >


/dev/null

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.

0 0,12 1 */2 * /sbin/ping -c 192.168.0.1; ls -la >>/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.

0 4 8-14 * * test $(date +\%u) -eq 7 && echo "2nd Sunday"

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 * * * *".

An example of crontab format with commented fields is as follows:

# Minute Hour Day of Month Month Day of Week Command


# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
0 2 12 * *
/usr/bin/find

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy