[an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] 24x7 Script Archive


Dynamically creating new and modifying existing jobs from a script

Use the following statments to dynamically create, delete, change, reschedule, enable, disable, and run jobs from a JAL script:

  • JobCreate
  • JobDelete
  • JobEnable
  • JobModify
  • JobDescribe
  • JobRun

Example 1 (creating brand new job):

// Create new job object
Dim job_id, number
JobCreate( job_id )

// Setup properties for the new job
    // Specify generic job properties
        JobModify( job_id, "NAME", "Dynamic job created from script" )
        JobModify( job_id, "DESCRIPTION", "This jobs starts RAS dialer in HOST mode" )
        JobModify( job_id, "JOB_TYPE", "P" )
        JobModify( job_id, "ASYNC", "Y" )
    // Specify job schedule
        JobModify( job_id, "SCHEDULE_TYPE", "O" )
        JobModify( job_id, "START_DATE", "1999-01-10" )
        JobModify( job_id, "START_TIME", "10:00" )
    // Set command line for RAS dialer
        JobModify( job_id, "COMMAND", "rasphone.exe" )
    // Wait 5 seconds to allow RAS dialer to initialize
        JobModify( job_id, "INIT_TIMEOUT", "5" )
    // Send keystroke to enter HOST mode then start Listener
        JobModify( job_id, "SEND_KEYSTROKE", "Y" )
        JobModify( job_id, "KEYSTROKE", "{ENTER}{ENTER}" )

//  Enable new job
JobEnable( job_id, TRUE )

Example 2 (changing job schedule):

// This job watches for several files on the remote FTP server. It is scheduled to run every 10 minutes.
// When all required files exist, it calls another job that downloads files then it reschedules itself to start on the next day

Dim found, boolean

// ... check for files on the remote FTP site
CHECK_ACCOUNTS:
        FTPFileExists( "ftp.myserver.com", "myname", "mypassword", "account.dat", found )
        if( found, CHECK_HOLDINGS, RETRY_LATER )
CHECK_HOLDINGS:
        FTPFileExists( "ftp.myserver.com", "myname", "mypassword", "holding.dat", found )
        if( found, CHECK_TRADES, RETRY_LATER )
CHECK_TRADES:
        FTPFileExists( "ftp.myserver.com", "myname", "mypassword", "trade.dat", found )
        if( found, GET_FILES, RETRY_LATER )
GET_FILES:
        JobRun( "FTP Downloader" )
SELF_RESHEDULE:
        Dim today, date
        Dim tomorrow, date
        Dim start_time, datetime
        Today( today )
        DateAdd( today, 1, tomorrow )
        DateTime( tomorrow, 11:30,  start_time )
        JobModify( "FTP Watcher", "START_TIME",  start_time )
        // all done
        exit

RETRY_LATER:
// this job will be automatically restarted in 10 minutes