Avanti Product Banner

avanti's TaskMaster ®
TaskMaster Lite (TMLite)
Tips & Tricks

When the TaskMaster Master NLM is loaded on a Server, it adds a more powerful batch processing engine (.NCF/.TSK) and integrates a task scheduler. These features allow TaskMaster to not only replace but exceed the capabilities and features found in Novell's 'officially unsupported' CRON (scheduler) utility.

Extended Command Tips / Tricks
Changing Name Space Use REN / RENDIR to change Originating Name Space for Directory / File
Clear DIR Tree (Files Only) Use DELTREE to clear the subdirectory tree structure (remove only files)
Quick File System Reports Use DIR to create quick File System reports
Replicate (Empty) DIR Tree Use XCOPY / SXCOPY to copy a subdirectory tree without copying any files

Task (.TSK) Tips / Tricks
Avoid Overlapping Tasks Avoid concurrent execution of a task; Suspend a task until another task completes
IF / WHILE Remote Conditional Tests Check task status, file(s) exist / in use, NLM loaded or volume mounted on Remote Server
Replace Text in String Replace text in string with text of same/shorter/longer length
Subroutines in a .TSK Implementing subroutines (GOSUB/RETURN) within a task script
Walk Directory Tree (Process Subdirectories) Traverse (walk) an entire directory tree processing each individual subdirectory in the tree

  Additional Information / Support Links
General FAQ Frequently Asked Questions (FAQs) about avanti's products
TaskMaster / TMLite FAQ Frequently Asked Questions (FAQs) about TaskMaster / TMLite
TaskMaster SYNC FAQ Frequently Asked Questions (FAQs) about TaskMaster's SYNC command

TaskMaster Batch Reference Batch Commands / Scripting Language Quick Reference for TaskMaster / TMLite
TaskMaster Command Reference Extended Console Commands Quick Reference for TaskMaster / TMLite
TaskMaster Manual (Complete) Latest Electronic Copy (.PDF) of the TaskMaster / TMLite User's Guide
TaskMaster Sample Tasks Example Tasks for TaskMaster / TMLite




Changing Name Space:

Using the options supported by the REN / RENDIR extended Local Console Commands, it is possible to change the Originating (Owning) Name Space of a Directory or File. The following examples demonstrate how to change the Name Space:

REN vol:path\filespec *.* /C [/D | /L | /M | /N]

In the above example, any file(s) matching the specified file pattern (vol:path\filespec) will have their Originating Name Space (/C) changed as specified (/D = DOS, /L = Long, /M = Mac, /N = NFS).


REN SYS:LOGIN\LOGIN.EXE *.* /C /L

In the above example, LOGIN.EXE residing in the SYS:LOGIN directory will have its Originating Name Space (/C) changed to Long (/L).


REN SYS:SYSTEM\*.NLM *.* /C /D

In the above example, all .NLM files in the SYS:SYSTEM directory will have their Originating Name Space (/C) changed to DOS (/D).


RENDIR SYS:NWFTP\*.* *.* /C /N

In the above example, all directories in the SYS:NWFTP directory will have their Originating Name Space (/C) changed to NFS (/N).

Notes:

  • Caution should be exercised when changing the Originating Name Space on a Macintosh file as the Resource Fork may be lost.
  • If the Originating Name Space of a directory or file is already set to the specified Name Space, no change or error occurs.
  • Support for the specified Name Space must have been previously enabled for the volume.



  • Clear DIR Tree (Files Only):

    Using the options supported by the DELTREE extended Local Console Command, it is possible to delete all of the files in a subdirectory tree without alerting the subdirectory tree structure (i.e., leaving the subdirectories intact). The following example demonstrates how to clear a subdirectory tree of only its files:

    DELTREE vol:path\*.* /K

    In the above example, the subdirectory tree structure under the source specification (vol:path) will be cleared of all files but the subdirectory tree structure will remain intact.




    Quick File System Reports:

    Using the options supported by the DIR extended Local Console Command, it is possible to collect and output highly selective information about the File System contents. The following examples demonstrate how the options supported by DIR can be combined to produce a slective report:

    Note: DIR supports output redirection (>vol:path\filename.ext) to send the output displayed on the Server screen to a file.

    List all entries in the SYS:SYSTEM directory:

    DIR SYS:SYSTEM

    List only those entries matching a specific pattern (*.NLM):

    DIR SYS:SYSTEM\*.NLM

    Change the pattern to a generic wild card (*.*), change the starting point to the root of the SYS Volume (SYS:), and recurse (/S - search) all directories in the directory tree beneath the starting point:

    DIR SYS:*.* /S         Note: Searches the entire SYS: Volume.

    Change the output to only provide bare information (/B - vol:path\filename.ext only, no entry information) for entries in the SYS Volume:

    DIR SYS:*.* /B /S

    Limit the bare output to entries in the SYS Volume with the Hidden attribute set (/A=H):

    DIR SYS:*.* /A=H /B /S         Note: Multiple /A option can be combined (i.e., /A=H /A=RO ...).

    Limit the bare output to entries in the SYS Volume without the Read Only attribute set (/A=-RO):

    DIR SYS:*.* /A=-RO /B /S         Note: Multiple /A option can be combined (i.e., /A=-H /A=-RO ...).

    Limit the bare output to entries in the SYS Volume which are Files (/-D = exclude Directories):

    DIR SYS:*.* /B /-D /S

    Limit the bare output to entries in the SYS Volume which are Directories (/-F = exclude Files):

    DIR SYS:*.* /B /-F /S

    Limit the bare output to entries in the SYS Volume Owned by Admin.ctx (/O=Admin.ctx):

    DIR SYS:*.* /B /O=Admin.ctx /S         Note: /O= cannot be used with /-O.

    Limit the bare output to entries in the SYS Volume without a valid Owner ID assigned (/-O):

    DIR SYS:*.* /B /-O /S         Note: /-O cannot be used with /O=.

    Limit the bare output to entries in the SYS Volume with Admin.ctx assigned as a Trustee (/R=Admin.ctx):

    DIR SYS:*.* /B /R=Admin.ctx /S         Note: /R= cannot be used with /-R.

    Limit the bare output to entries in the SYS Volume with an invalid Trustee assigned (/-R):

    DIR SYS:*.* /B /-R /S         Note: /-R cannot be used with /R=.

    Limit the bare output to entries in the SYS Volume with a Size of 1 KB (/L=1024):

    DIR SYS:*.* /B /L=1024 /S

    Limit the bare output to entries in the SYS Volume with a Size of 1 MB or less (/L=-1048576):

    DIR SYS:*.* /B /L=-1048576 /S

    Limit the bare output to entries in the SYS Volume with a Size of 2 MB or more (/L=+2097152):

    DIR SYS:*.* /B /L=+2097152 /S

    Limit the bare output to entries in the SYS Volume with a Size between 1 MB and 2 MB (/L=1048576-2097152):

    DIR SYS:*.* /B /L=1048576-2097152 /S

    Limit the bare output to entries in the SYS Volume that were Created on 26 July 2004 (/T=C2004/07/26):

    DIR SYS:*.* /B /S /T=C2004/07/26         Note: Last Accessed Date   /T=A...   |   Last Modified Date   /T=M...

    Limit the bare output to entries in the SYS Volume that were Created on or before 26 July 2004 (/T=C-2004/07/26):

    DIR SYS:*.* /B /S /T=C-2004/07/26         Note: Last Accessed Date   /T=A-...   |   Last Modified Date   /T=M-...

    Limit the bare output to entries in the SYS Volume that were Created on or after 26 July 2004 (/T=C+2004/07/26):

    DIR SYS:*.* /B /S /T=C+2004/07/26         Note: Last Accessed Date   /T=A+...   |   Last Modified Date   /T=M+...

    Limit the bare output to entries in the SYS Volume that were Created between 21 - 26 July 2004 (/T=C2004/07/21-2004/07/26):

    DIR SYS:*.* /B /S /T=C2004/07/21-2004/07/26         Note: Last Accessed Date   /T=A...   |   Last Modified Date   /T=M...


    Combined Custom Report Examples:
    Note: While multiple /A options can be specified, the /L /O /R /T options are limited to using one of each at a time (i.e., the different options can be combined but only one form of each option can be used).

    Produce a normal listing of only Files with a .MPG extension in or below the SYS:HOME base directory that are 2 MB or larger:

    DIR SYS:HOME\*.MPG /-D /L=+2097152 /S

    Produce a normal listing of all new File System entries in the SYS Volume Created on 27 July 2004:

    DIR SYS:*.* /T=C2004/07/27 /S

    Produce a bare output listing of all *.NLM Files in the SYS:SYSTEM directory without a valid Owner assigment:

    DIR SYS:SYSTEM\*.NLM /B /-D /-O         Note: Unless /S is specified, the listing contains only the file names, not the vol:path.

    Produce a bare output listing of all entries in the SYS Volume Owned by Admin.ctx Created between 01 - 31 July 2004 of a Size of 1 MB or larger:

    DIR SYS:*.* /B /L=+1048576 /O=Admin.ctx /S /T=C2004/07/01-2004/07/31



    Replicate (Empty) DIR Tree:

    Using the options supported by the XCOPY extended Local Console Command and the SXCOPY extended Remote Console Command, it is possible to replicate (copy) a subdirectory tree structure locally / remotely without copying any of the files which reside therein. The following examples demonstrate how to replicate (copy) the directory tree structure (only) without including any of the files therein:

    XCOPY srcvol:srcpath\zyxwvuts.xyz dstvol:dstpath /E /S

    In the above example, the subdirectory tree structure under the source specification (srcvol:srcpath) will be copied to the destination specification (dstvol:dstpath).

    SXCOPY srcvol:srcpath\zyxwvuts.xyz rserver/dstvol:dstpath /E /S

    In the above example, the subdirectory tree structure under the local source specification (srcvol:srcpath) will be copied to the Remote Server destination specification (rserver/dstvol:dstpath).

    Notes:

  • The trick is the combination of an invalid file specification with the /E (Empty Subdirectories) and /S (Subdirectory recursion) options. The /S option tells SXCOPY / XCOPY to recurse the subdirectory tree, creating any destination subdirectories that do not exist. By default, any newly created destination subdirectory is deleted if no files are copied into it but the /E option overrides the deletion. Using an invalid file specification insures that no files are copied, only the subdirectory tree structure.
  • This same technique works with DOS / Windows XCOPY.



  • Avoid Overlapping Tasks:

    TaskMaster supports concurrent and multiple task execution by providing each task with its own Current Working Directory (CWD) and stack. Depending upon the task schedule and the operations performed within the task, it is possible for a scheduled task to begin execution prior to the completion of a previous iteration of the same task. There are also situations where it can be important to assure the completion of a separate task prior to execution of the current task.

    Avoid Concurrent Execution of a Task:
    Logic can be added to a task to insure that the same task does not execute if a previous iteration of the task, or a separate task, is active.

    • The following tests if the same task is already executing and terminates the new task if the test succeeds:

                IF ACTIVE_TASK %TASK% THEN EXIT
                

      Note: The name of a different task (TASKNAME.EXT) can be be substituted for the %TASK% System Environment Variable to confirm completion of a different task.

    • The following assumes the output of a command executed within the task has been redirected to a log file (using the optional output redirection). The logic checks if the log file is still in use (i.e., the command executed within the task is still active) and terminates the new task if the test succeeds (i.e., the file is in use):

                IF FILE_IN_USE vol:path\filespec.ext THEN EXIT
                

      Note: The name of the appropriate output redirection file should be substituted for vol:path\filespec.ext.

    Suspend A Task Until Another Task Completes:
    Logic can be added to a task to insure that the task does not execute until a previous iteration of the task or a separate task completes.
    • The following tests if the specified task is executing and puts the current task to SLEEP until the first task completes (rechecking every 15 seconds and remaining in the WHILE/LOOP until the first occurrence of the task completes):

                WHILE ACTIVE_TASK [PREVTASK.TSK]
                  SLEEP 15
                LOOP
                

      Note: The name of the appropriate task should be substituted for the bracketed ([]) PREVTASK.TSK task name (exclude the brackets). The name of the current task can be automatically assumed via the %TASK% System Environment Variable to suspend concurrent execution of the same task.

    • The following assumes the output of a command within the specified task has been redirected to a log file (using the optional output redirection) and puts the current task to SLEEP until the file is no longer in use (rechecking every 15 seconds and remaining in the WHILE/LOOP until the file is closed):

                WHILE FILE_IN_USE [SYS:SYNC.LOG]
                  SLEEP 15
                LOOP
                

      Note: The name of the appropriate output redirection file should be substituted for the bracketed ([]) SYS:SYNC.LOG file name (excluding the brackets).



    IF / WHILE Conditional Tests for Remote Server

    Effective with TaskMaster v4.11, the following IF / WHILE conditional tests are supported for Remote Server access (previously limited to Local Server support only):

          ACTIVE_TASK    ex. IF ACTIVE_TASK RSERVER/tsk_name[.ext]
          EXIST(S)       ex. IF EXISTS RSERVER/vol:\path\filespec[.ext]
          FILE_IN_USE    ex. IF FILE_IN_USE RSERVER/vol:\path\filespec[.ext]
          LOADED         ex. IF LOADED RSERVER/nlm_name[.ext]
          MOUNTED        ex. IF MOUNTED RSERVER/volume
          
    Further information along with sample usage can be found in the TaskMaster v4 User's Guide (v4.11 or later).



    Replace Text in String

    The following logic will substitute a word for another word in a string, regardless of whether the two words are the same length or not...

          // Replace a word in a string (in this example, 'that' for 'which')
    
          // Alias some base dynamic variables to make script easier to read and follow
    
          VARALIAS %0 %OLD_STRING%
          VARALIAS %1 %NEW_STRING%
          VARALIAS %2 %OFFSET%
    
    
          // Define the base string needing to be changed
    
          DEFINE %OLD_STRING% This is the main string that needs to be modified...
    
    
          // Locate offset of ' that ' (note leading/trailing space to isolate word)
    
          FINDSTR %OFFSET% " that " "%OLD_STRING%"
    
    
          // Move contents up to 'that' (old word) from old string to new string
    
          PARSE %NEW_STRING% %OLD_STRING% 1-%OFFSET%
    
    
          // Append 'which' (new world) to new string
    
          DEFINE %NEW_STRING% %NEW_STRING%which
    
    
          // Adjust offset in old word to trailing space following 'that' (old word)
          // (i.e., 5 = length of 'that' plus leading space)
    
          CALC %OFFSET% %OFFSET% + 5
    
    
          // Move contents following 'that' from the old string to new string
          // Notes: Specify APPEND to avoid overwriting previously stored contents.
          //        Specify length longer than expected and use PACK to truncate.
    
          PARSE %NEW_STRING% %OLD_STRING% %OFFSET%-255 APPEND PACK
    
    
          // Display the two strings to demonstrate the change...
    
          ECHO %%OLD_STRING%% = '%OLD_STRING%'
          ECHO %%NEW_STRING%% = '%NEW_STRING%'
          



    Subroutines in a .TSK:

    There are occassions within task logic where it would be convenient to be able to transfer processing to (GOTO) a different part of the task script, yet be able to return back after executing the special commands. Some versions of BASIC and scripting languages provide such capabilities via CALL or GOSUB commands. TaskMaster's scripting language does not currently support GOSUB and implements the CALL command similar to DOS batch processing (i.e., suspend processing of the current task until a separate task script, specified by the CALL command, completes processing). However, due to TaskMaster's dynamic variable support, it is possible to implement the GOSUB functionality in the current release.

    Note: Normally, it is not advised to use GOTO commands which redirect (or jump) the logic flow out of an IF / ENDIF or WHILE / LOOP construct. While this example utilizes GOTO redirection outside of a WHILE / LOOP construct, it is considered safe because the logic where the flow jumps to includes a GOTO which returns execution back within the construct without any further redirection (i.e., the flow jumps out of the construct and then jumps right back in without any further redirection).

    The following example searches a specific set of subdirectories for a specific set of filenames / extensions:

          //====================================================================
          // Uses four of the dynamic System Environment Variables (%0-%9)
          // %0  Index to first/next label to retrieve subdirectory list
          // %1  Used to retrieve/check each item in the subdirectory list
          // %2  Index to first/next label to retrieve filename/extension list
          // %3  Used to retrieve/check each item in the filename/extension list
          //--------------------------------------------------------------------
    
          // Setup up subdirectory label index counter for initial use
    
          DEFINE %0 00
    
    
          WHILE
    
              // Increment subdirectory label index counter then
              // GOTO the matching label to retrieve the first/next subdirectory
    
              DEFINE %0 %0+=01
              GOTO GET-SUB-%0
    
    
              // Return label for GOTO GET-SUB-%0 processing
    
              :PROC-SUB
    
    
              // Check if returned subdirectory (%1) is NULL (i.e., no more)
    
              IF "%1"=="" THEN BREAK
    
    
              // Set Current Working Directory (CWD) to the retrieved subdirectory
    
              CD %1
    
    
              // Setup up filename/extension label index counter for initial use
    
              DEFINE %2 00
    
    
              WHILE
    
                  // Increment subdirectory label index counter then
                  // GOTO the matching label to retrieve the first/next filename/ext
    
                  DEFINE %2 %2+=01
                  GOTO GET-FILE-%2
    
    
                  // Return label for GOTO GET-FILE-%0 processing
    
                  :PROC-FILE
    
    
                  // Check if returned filename/ext (%1) is NULL (i.e., no more)
    
                  IF "%3"=="" THEN BREAK
    
    
                  // Check if filename/extension exists and process accordingly
    
                  IF EXIST %3
    
                      // Process matching file in specified subdirectory
    
                  ENDIF
    
              LOOP
    
          LOOP
    
    
          // Finished processing all filenames/extensions for each subdirectory
    
          EXIT
    
    
          // The individual labels which each DEFINE a different subdirectory
    
          :GET-SUB-01
          DEFINE %1 SYS:PUBLIC
          GOTO PROC-SUB
    
          :GET-SUB-02
          DEFINE %1 SYS:SYSTEM
          GOTO PROC-SUB
    
          // No more subdirectories need processing so return a NULL value
    
          :GET-SUB-03
          DEFINE %1
          GOTO PROC-SUB
    
    
    
          // The individual labels which each DEFINE a different subdirectory
    
          :GET-FILE-01
          DEFINE %3 *.BAK
          GOTO PROC-FILE
    
          :GET-FILE-02
          DEFINE %3 *.TMP
          GOTO PROC-FILE
    
          :GET-FILE-03
          DEFINE %3 INFECTED.EXE
          GOTO PROC-FILE
    
          // No more subdirectories need processing so return a NULL value
    
          :GET-FILE-04
          DEFINE %3
          GOTO PROC-FILE
    
          //====================================================================
          


    Walk Directory Tree (Process Subdirectories)

    The following .TSK script logic will traverse (walk) an entire directory tree processing each individual subdirectory in the tree:

          Note: Lines starting with // are comments.
          
    
          // Replace [base_dir] with directory tree VOL:PATH to traverse.
          // CHDIR [base_dir] will set the Current Working Directory (CWD) to
          // the [base_dir] specified VOL:PATH.
    
          CHDIR [base_dir]
    
    
          // Set Defined Variable %0 to null ("") in case used previously in task
    
          DEFINE %0
    
    
          // WHILE / LOOP starts in [base_dir] then traverses directory tree one
          // subdirectory each LOOP by issuing %DIR_TREE_% using the CWD (%CWD%)
          // for the first pass and no specification for subsequent passes.
          // At bottom of directory tree, %DIR_TREE_% will return a null ("").
    
          WHILE
    
    
              // Insert logic after this comment for processing each subdirectory
              // beginning with [base_dir] and traversing down directory tree.
              // In this example, echo (display) the CWD for each subdirectory.
    
              ECHO %CWD%
    
    
              // If %0 is null (""), it is first WHILE / LOOP so include Current
              // Working Directory (%CWD% in %DIR_TREE_%CWD%%) to specify directory
              // tree to walk.  Subsequent (next) usage does not require a spec.
              // Get first (%CWD%) / next (no spec) subdirectory in directory tree.
    
              IF "%0"==""
    
                  DEFINE %0 %DIR_TREE_%CWD%%
    
              ELSE
    
                  DEFINE %0 %DIR_TREE_%
    
              ENDIF
     
    
              // Check retrieved value (%0) and break if null else LOOP to WHILE
    
              IF "%0"=="" THEN BREAK
    
          LOOP