Cover V03, I06
Article
Figure 1
Figure 2
Listing 1

nov94.tar


A Shell-Based Resource Scheduler

Packey Velleca

People often have to share resources: rooms, computers, test equipment, devices, anything that is limited in quantity. Scheduling these resources by a central authority is frequently the best way to manage them. This article presents a powerful tool for such a manager: a UNIX csh script, sched (Listing 1), that is capable of scheduling resources. The program provides an easy-to-use menu, two report formats, and PostScript printing.

This script was designed with the following goals:

  • It should allow quick and easy resource scheduling.

  • Its output should be flexible to generate and easy to read.

  • It should be easy to install, and should provide useful default settings.

  • It should be easily modified and maintained by an administrator with entry-level programming skills.

    The tool, sched, meets these goals:

  • sched was written in csh script, which is easy to learn and highly portable.

  • sched provides two report formats and selectable PostScript printing.

  • sched includes a completely automated installation script with recommended defaults.

  • sched, a csh script, is easy to modify.

    Operation of the Scheduler

    sched is a resource scheduler. For example purposes, this article assumes that the resource being scheduled is machine time on a set of hosts. Hosts are added to a host list, then reservations can be made, changed, or deleted, and daily and weekly schedules can be printed.

    All scheduling operations are from a Master hardcopy generated by sched. All inputs are made with respect to a Master schedule, which must be reprinted each time reservations are modified.

    Syntax

    Input syntax is consistent throughout the program. Single dates are entered as "month/day," such as 3/24 or 11/1, with month and day separated by a slash (/). A year is not required or used. A range of dates is entered as "month/day-month/day," such as 3/24-11/1. Reservations can be made up to 12 months in advance, including in advance of the current month. This means that if the current month is March, reservations can be made for all months up to and including February. Attempts to reserve more than 12 months in advance are treated as months for the current year. The program verifies date syntax.

    Times are entered as ranges in military units, such as 0800-0830 or 1400-1730. Start and end times are each four digits and must be separated by a hyphen (-). The largest block of time is 0000-2400, one whole day, and the smallest is equal to one time slot, as defined in the .template file. The program checks time syntax.

    Each time the program is run, a cleanup routine checks for old reservations from the first of the current month up to, but not including, the current day. If any old reservations exist, they are deleted. For example, any reservations for March 1-9 would be deleted when the program is run on March 10.

    Maneuvering through the Menus

    Selecting a choice from a menu usually results in a prompt for further action. For some functions, prompts are nested until all information is obtained. Entering a carriage return with no input at a prompt returns to the previous menu level or prompt. An "m" for menu, entered at any prompt nested more than one level, or entered at a status message, returns to the main menu. The main menu looks like this:

    Status:  PS[ON]  PR[lp]  RPT[MATRIX]
    
    MAIN MENU
    ==== ====
    
    1       Add HOST
    2       Delete HOST
    3       List HOST
    
    4       Reserve HOST
    5       Delete Reservation
    
    6       Printing
    
    0       Exit
    
    CHOICE?

    Add Host

    This selection adds a host to the host list. Hosts can't be reserved until they are in the host list. Names will be cut to 15 characters or less. Only unique host names will be added. You can add multiple hosts at once by separating their names with whitespace.

    Delete Host

    This selection deletes a host from the host list, along with all reservations set for that host. Specify host names exactly as they appear in the list. You may delete more than one host at a time by separating host names with whitespace. To delete all hosts and their reservations at once, specify "ALL" as the hostname.

    List Host

    This menu selection uses more to display the host list in alphabetic order to the screen. You can generate a hardcopy of the host list by printing the .resourcelist file.

    Reserve Host

    To reserve a host, you specify the date or range of dates, the host name, the reserver, and the time. You may reserve hosts multiple days at a time by specifying a range of dates. Only hosts in the host list can be reserved. The reserver's name will be cut to 15 or fewer characters. If any portion of a requested reservation is already reserved by someone else, the whole newly requested reservation will be cancelled -- no new time slots will be reserved at all.

    Delete Reservation

    To delete a reservation, specify the date, the host name, and the time slot. You may delete an entire reservation or any smaller part of it. Note that reservations are deleted by time slots, not by reserver, so that one delete command can remove the reservations of multiple reservers. Reservations can only be deleted one day at a time. Deleting a reservation for three days requires three separate deletions. Only reservations for hosts in the host list can be deleted. Delete all currently scheduled reservations by specifying "ALL" when prompted for a deletion date.

    Printing Reports

    Selecting the printing option pulls up a printing submenu with eight choices:

    Status:  PS[ON]  PR[lp]  RPT[MATRIX]
    
    PRINTING MENU
    ======== ====
    
    ONE DAY REPORT
    1     All HOSTS
    2     One HOST
    
    ONE WEEK REPORT
    3     All HOSTS
    4     One HOST
    
    ALL RESERVATIONS
    5     All HOSTS
    6     One HOST
    
    7     Set Printing Defaults
    
    0     Exit Printing Menu
    q     Quit Program
    
    CHOICE?

    Print output can be directed to the screen, a file, a printer, or to both a file and a printer. Screen output pipes through more. File output goes to a default filename or to a name you choose. If output goes to an existing file, that file's contents will be overwritten. Printer output goes to a default printer.

    Print One Day for All Hosts

    This selection prompts for a date, and prints all reservations for that date.

    Print One Day for One Host

    This selection prompts for a date and a host, and prints all reservations for that host on that date.

    Print One Week for All Hosts

    This menu selection prompts for a date, and prints all reservations for all hosts for the week that contains that date, Saturday through Sunday. For example, the calendar for September and October 1993 was:

      September 1993
    
    S  M Tu  W Th  F  S
    1  2  3  4
    5  6  7  8  9 10 11
    12 13 14 15 16 17 18
    19 20 21 22 23 24 25
    26 27 28 29 30
    
    October 1993
    
    S  M Tu  W Th  F  S
    1  2
    3  4  5  6  7  8  9
    10 11 12 13 14 15 16
    17 18 19 20 21 22 23
    24 25 26 27 28 29 30
    31

    Specifying a date of 10/6 or 10/7 will print reservations for the dates 10/3 through 10/9. Specifying a date of 10/1, 10/2, or 9/29 will print the reservations for 9/26 through 10/2. Specifying a date of 10/31 will print reservations for 10/31 through 11/6.

    Print One Week for One Host

    This selection prompts for a date and a host, and prints all reservations for that host for the week containing that date.

    Print All Reservations for All Hosts

    This menu selection prints all reservations currently scheduled.

    Print All Reservations for One Host

    This selection prints all reservations currently scheduled for one host.

    Set Printing Defaults

    This selection pulls up a submenu with three options for setting program defaults:

    PRINTING DEFAULTS MENU
    ======== ======== ====
    
    1  Postscript printing is:    ON
    2  Default printer is:        lp
    3  Default report format is:  MATRIX
    
    0  Exit Printing Defaults Menu
    q  Quit Program
    
    CHOICE?

    Each default setting is displayed on a status line in all parent menus.

    PostScript Printing

    This selection toggles PostScript printing ON|OFF. If ON, hardcopy goes to the default printer in PostScript. Otherwise it will be sent as ASCII. PostScript printing is recommended.

    Printer Selection

    To change the default printer, select this menu setting and enter a valid system printer name. This printer will become the new default printer until the default is changed again.

    To change the printer while running sched, set the default printer to NONE. This state forces the program to prompt the operator interactively for the printer name during printing. For the rest of the session, that printer will be the default printer. If the program is terminated and restarted, the printer will default back to NONE for the next session.

    Report Format

    Selecting this menu setting toggles the report style MATRIX|FLAT. If MATRIX, the report will print one day per page, graphically depicting all time slots whether they are reserved or not. FLAT produces a simple tabular report showing only reserved time slots. MATRIX reports are the default, and are recommended. Figure 1 shows a sample of the MATRIX format report. Figure 2 shows the same report as FLAT.

    Implementing sched

    I believe you and your users will find this scheduling tool a very handy resource. The electronic code distribution for this issue contains a full implementation. See the inside contents page for Online Source Code information.

    About the Author

    Packey Velleca currently works with a group of administrators for a small system of real-time computers with UNIX-based operator workstations. He graduated from Florida Institute of Technology in Melbourne, FL, with a BSEE in 1988.


     



  •