[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


24x7 API - Examples of Using Job Definition Language Commands

1. Command Files

The following is an example of using JDL.FILE via DOS command line interface includes. This example includes two files: EXAMPLE.JDL and JDL.BAT. Note that the JDL.BAT file is universal. You can use it in your projects as is.

JDL.BAT

@echo off
echo the 24x7 Scheduler
echo Processing JDL command file %1%
24x7 /SCRIPT %1%
type jdl.log


EXAMPLE.JDL

; Change name for the job #1
SET 1 NAME=JDL command file test 1
; Change start-in directory for the job #2
SET 2 STARTIN=c:\windows
; Add the new job to the schedule
ADD
    NAME=New job submited via JDL command file
    COMMAND=notepad
    ASYNC=N
    TIMEOUT=1
    DESCRIPTION=This jobs was created using JDL command file
; Save all changes
SAV


To try this example:
  1. Create both required files
  2. Make sure the 24x7 Scheduler is running
  3. From the DOS promt type JDL EXAMPLE.JDL


2. DDE interface

This example shows how to use Visual Basic to execute JDL commands using DDE protocol.

Attribute VB_Name = "24x7"
Option Compare Database
Option Explicit

Sub Macro_24x7( )
'
' Establish DDE link to the 24x7 Scheduler and send some JDL commands
'
'
    Dim ChannelNumber As Long, NewJob As Long, JobName As String


    ' initiate DDE conversation
    ChannelNumber = Application.DDEInitiate("the 24x7 Scheduler", "JDL")

    ' get job #1 name
    JobName = DDEGetValue(ChannelNumber, "1" + Chr(9) + "NAME")

    ' disable job #1
    Call DDEDisable(ChannelNumber, "1")
    ' or alternatively perform the same operation using job name
    ' instead of using job number. This works for all commands
    ' Call DDEDisable(ChannelNumber, JobName)

    ' change job #1 name
    Call DDESetValue(ChannelNumber, "1" + Chr(9) + "Name", "New Name for job #1")

    ' delete job #1
    Call DDEDelete(ChannelNumber, "1")

    ' add new job
    NewJob = DDEAdd(ChannelNumber)

    If NewJob > 0 Then ' set new job properties
        Call DDESetValue(ChannelNumber, CStr(NewJob) + Chr(9) + "Name", "New Name")
        Call DDESetValue(ChannelNumber, CStr(NewJob) + Chr(9) + "Command", "c:\feed\mfeed.exe /S")
        Call DDESetValue(ChannelNumber, CStr(NewJob) + Chr(9) + "Start_Time", "19:30")
        Call DDESetValue(ChannelNumber, CStr(NewJob) + Chr(9) + "Async", "N")
        Call DDESetValue(ChannelNumber, CStr(NewJob) + Chr(9) + "Timeout", "30")
    End If

    ' save all changes
    Call DDESave(ChannelNumber)

    ' terminate DDE conversation
    Application.DDETerminate ChannelNumber
End Sub

Function DDEGetValue(ChannelNumber As Long, Location As String) As String
    DDEGetValue = Application.DDERequest(ChannelNumber, Location)
End Function

Sub DDESetValue(ChannelNumber As Long, Location As String, Data As String)
    Application.DDEPoke ChannelNumber, Location, Data
End Sub

Sub DDEDisable(ChannelNumber As Long, Location As String)
    Application.DDEExecute ChannelNumber, "DIS " + Location
End Sub

Sub DDEEnable(ChannelNumber As Long, Location As String)
    Application.DDEExecute ChannelNumber, "ENA " + Location
End Sub

Sub DDEDelete(ChannelNumber As Long, Location As String)
    Application.DDEExecute ChannelNumber, "DEL " + Location
End Sub

Sub DDESave(ChannelNumber As Long)
    Application.DDEExecute ChannelNumber, "SAV"
End Sub


Function DDEAdd(ChannelNumber As Long) As Long
    Application.DDEExecute ChannelNumber, "ADD"
    DDEAdd = DDEGetValue(ChannelNumber, "NEW_ID")
End Function


To try this example:

  1. Copy example code to the application supporting either Visual Basic or Visual Basic for Applications programming language
  2. Make sure the 24x7 Scheduler is running
  3. Run Macro_24x7 macro

 

  • Important note:
    The example above will not work in Microsoft Excel because of Excel specifics