Setup user define task in DB Scheduler

Technote (troubleshooting)


Problem(Abstract)

How to create a user define task that run periodically to perform administrative work?

Resolving the problem

Like a lot of fellow System Administrator, you may need to execute many system or administrative works automatically. Some of these works should occur at regular intervals. Other works need to run only once, perhaps during off hours such as evenings or weekends. You can use the Informix DB Scheduler to create a user define task to run administrative work automatically in the background at predictable times. The DB Scheduler uses SQL statements instead of operating system job scheduling tools, e.g., cron job.

In this document you will see an example of user define task that delete some unwanted files on a periodic basis. For better understanding you can perform this work in two phases.

    1. Create a stored procedure that performs the actual delete operation.
    2. Define a task that that executes the above stored procedure in certain interval.

Create a stored procedure
First you are creating a procedure under 'sysadmin' database named 'delete_apb_documents_proc()' that removes all files as 'apb_document*' from /tmp directory which accessed more than 60 minutes ago.
    CREATE PROCEDURE sysadmin:delete_apb_documents_proc()

    DEFINE cmd CHAR(80);
    LET cmd = "find /tmp -maxdepth 1 -type f -name 'apb_document*' -amin +60 -exec rm {} \;";
    SYSTEM cmd;

    END PROCEDURE;
Use the UNIX manual page for 'find' command (man find) to get details on options used in the above example.


Define a task
Next, defining a task named 'delete_apb_document()' which runs top of each hours and execute the procedure delete_apb_documents_proc().

    INSERT INTO sysadmin:ph_task
    (
    tk_name,
    tk_group,
    tk_description,
    tk_type,
    tk_execute,
    tk_start_time,
    tk_stop_time,
    tk_frequency
    )
    VALUES
    (
    "delete_apb_document",
    "MISC",
    "Remove apb_document files from /tmp directory that last accessed 60 minutes ago",
    "TASK",
    "EXECUTE PROCEDURE sysadmin:delete_apb_documents_proc(); ",
    "01:00:00",
    "23:00:00",
    INTERVAL ( 60 ) MINUTE TO MINUTE
    );
Check the Informix Information Center to get more information on define a task.

You can run all the above SQL statements against 'sysadmin' database using dbaccess utility.


Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

Informix Servers

Software version:

11.1, 11.5, 11.7

Operating system(s):

AIX, HP-UX, Linux, Mac OS X, Solaris, Windows

Reference #:

1617258

Modified date:

2013-01-14

Translate my page

Machine Translation

Content navigation