CRONY™ (Chapter 9)

9.1 Managing 'cron' and 'crontab' with Crony™  Back To Top

Commands to be executed by cron are placed in a crontab file consisting of lines with five fields specifying when the command will run, followed by the command itself.

You should specify time of execution by either the day of the week or by the date. If one specifies both the day of week and a date, the command will be executed twice when the two coincide.

Crony automates managing your crontab file for you, by allowing you to specify a command, and then set the time when it will run, allowing no duplication of times within one command.

Managing cron and crontab with Crony. To prevent conflicts in time of execution between the commands in the crontabs of any or all users, Crony provides two listings:

One a detailed summary of each user's crontab commands, and the other a time ordered listing of all crontab commands that might be executed on any one day. Use these to avoid collisions. These are available only to a user with root powers.

All of the features of Crony are available internally, simply by executing it, but the previously mentioned crontab listings may be obtained by executing Crony with certain switches. For more information about this, execute: crony -v.

One final caution:

Do not schedule cron jobs to start during the hours when your locality changes to or from daylight savings (summer) time to standard time, and vice versa, unless you fully understand the workings of cron on your system. (You may be surprised when a command executes twice, or at a time different from what you had anticipated.)

Syntax: Crony [-a | -t]

9.2 General Information  Back To Top

Executed simply, with no arguments, Crony presents a menu and prompted user interface for reviewing, editing, adding, deleting, inactivating and activating crontab command lines, the lines that tell cron what commands to execute and when to execute them.

The -a argument causes Crony to write, to its standard output, a listing of all crontab commands, sorted by user name, in a format making it easy to understand by those not familiar with crontab.

The -t argument causes Crony to write, to its standard output, a time ordered listing of all commands that will be executed by cron. It is useful for assuring that crontab commands are not duplicated, and that they are spaced in time so that the system's resources are efficiently used.

The -a and -t arguments can be used only by a user with root power, and the command should be piped to the pager program of one's choice, to a printer, or to a file, with command lines such as:

crony -a | more
or
crony -t | more

The same reports are available within Crony as menu choices on the Utility Menu (if the user is root), where the options are to write to the screen, file, or printer. In the latter case the user has the option of the default printer (lpr -s, or the printer named in the environmental parameter Printer), or of naming a printer. If the user elects, within Crony, to view these reports on the screen, the Unix command more is used by default, unless the environmental paramete PAGER is set to a value indicating the pager program of one's choice.

< a>Executing Crony with any arguments other than those specified above will result in a usage message (including the Crony version number) being written on the terminal screen.

9.3 Using Crony  Back To Top

Upon executing Crony, the user is presented with the menu. 

The top line of the screen indicates the user whose crontab entries are being managed with Crony at this time.

Choice 1 - Each of the user's crontab entries, if any, are presented for review. If none exist, the program goes directly to the Adding Crontab Commands Menu.

Choice 2 - Allows the user to review only those crontab lines that contain a certain key word. One may choose from a prompt to select only Lone-Tartm command lines, or other command lines that would match a keyword entered by the user.

Choice 3 - Takes one directly to the Adding Crontab Commands menu.

Choice U - Presents the Crony Utility Menu.

Choice Q - Quits the program.

9.4 Reviewing Crontab Command Lines  Back To Top

When reviewing crontab command lines, the screen displays the line number of the command in the crontab file, the command line itself, a plain English translation of when the command will be executed, and a prompt line.

The prompt line changes according to what options are permitted at the time, but the primary prompt line allows these options:

Edit - Allows editing the command itself, or when it should run.

Delete - Permits deletion of a crontab command line.

Inactivate - Places a # as the first character of the crontab line.

Next - Reviews the next crontab command line in the file, if any.

Prev - Reviews the previous crontab command line, if any.

Quit - Quits reviewing crontab command lines.

The only way to quit reviewing crontab command lines is to enter q when Quit is one of the options on the displayed prompt line. The user is then given the choice whether or not to add crontab command lines.

An option to Activate will be a part of the prompt line if a crontab command line has been inactivated. If one deletes a crontab command line, the only options remaining will be Next, Prev, or Quit.

If, on entering a Next or Prev choice, the bounds of the records in the crontab file (or of those selected by entering a keyword via menu Choice 2) are encountered, the prompt line will be modified by either the words FIRST Record or LAST Record, as applicable, inserted at the beginning of the prompt line.

If a crontab command line is deleted during a session in the review mode of Crony, it will not there-after be found with the Next/Prev options. For it to be retrieved, the user must Quit the review mode, respond q to the Update/Quit prompt and then execute Crony again.

After one Edits, Inactivates, Activates or Deletes a crontab command line, the headline of the review screen will indicate the action that has just taken place.

9.5 Adding Crontab Command Lines  Back To Top

The first step in adding a crontab command line to be executed by cron is to enter the command itself. The user will be given the option to add Lone-Tar(tm) commands from a menu, or to type in any desired command.

The next step, specifying when cron should execute the command, is explained below.

9.6 Assigning or Editing When 'cron' Should Execute Commands  Back To Top

There are but two reasonable ways to specify to cron when it should execute commands:

1. On specified days of the week

2. In specified Months on specified Dates

On electing either of these, a series of menus will prompt for the necessary information to complete a ''when to execute'' specification.

After a command has been entered, and the time(s) cron should run it have been specified, the user is placed in the review mode to give final approval to the new crontab command line. At this time, the crontab command line is subject to all of the operations available for previously existing crontab command lines.

Additionally, all of the pre-existing crontab command lines (except those deleted during the current Crony session) will be available for further review with the Next/Prev options, even if the user entered the original review by a keyword search (from Choice 2 on the main menu), or by the ADD crontab commands (Choice 3).

When editing an existing crontab command line for when cron should execute the command, an additional menu choice is made available:

E - Edit Hours/Minutes Only

Use this option when the only change needed is in the time(s) of day a crontab command should be executed by cron.

You may abort assigning or editing when a command should be executed by selecting the menu choice to Cancel Editing (or Adding) the command on any of the menus in this section of the program.

9.7 Security Blanket  Back To Top

Before exiting Crony the user will see the prompt:

Update cron or Quit ?

NO CHANGES WILL BECOME EFFECTIVE unless and until the response of u is entered at this prompt. A response of q will abort all changes made during the session, and quit the program.

A response of u will show something like:

Crony - Managing crontab for ''root'':
 

Update cron or Quit ? u
 

UPDATING the crontab file for ''root'' . . .
 

COMMAND: crontab .cron.root
 

SUCCESS

The crontab file for root has been written; cron has been updated.

The file .cron.* (where * is the user's logname) will then be in the current working directory. It is a copy of the crontab file that has now been put into force.

9.8 The Utility Menu  Back To Top

The utility menu displays options that are available to the user, so regular users will not see those available only to the root user (which are options 2, 3 and 4).

Choice 1 offers a brief discussion of Crony, cron and crontab.

Choices 2 and 3 produce from within Crony the reports available with the -a and -t command line switches discussed earlier.

Choice 4 allows root to execute Crony to manage the crontab file of any other user on the system, so long as that user is permitted to submit cron jobs. (Note: Crony will permit formulating crontab command lines for any valid user, but crontab will not install the commands if that user lacks authorization to use cron.)

Choices 2, 3 and 4 do not appear on the menu for regular users.

Choice H displays this helpfile if it is found as README.Crony in the directory $LTAR_HOME (/usr/lone-tar by default). If it is not so found, this option will not appear on the Utility Menu.

9.9 An Example of Using Crony  Back To Top

The following is an example of adding a useful crontab command line.

It is not possible, in one crontab command line, to specify that cron execute commands only on the last day of every month. But here is a simple way to do so.

Use your favorite editor to type in the shell script eom:

:

# @(#) eom - eecute commands on the last day of a month

# assumes the value of TZ is in the form: EST5EDT

tz=\Qecho $TZ | awk '

{ L=length($0) # length of the value of the TZ parameter 
st=substr($0,1,3) # first 3 characters of the TZ parameter

dt=substr($0,L-2) # final 3 characters of the TZ parameter

hd=substr($0,4,L-6) # hours between the local time zone and GMT

hd=hd - 24 # wind the hands of the clock 24 hours forward

print st hd dt }'\Q

[ ''\QTZ=$tz date '+%d'\Q'' -ne 1 ] && exit 0 # NOT End-Of-Month

# commands to be executed on the last date of the month go below:

# EOF 'eom'

Place the command(s) you want executed on the last day of every month in the line(s) just above the final line, make the script executable with the command chmod a+x eom, and move it to the directory where you keep local programs.

Execute Crony, electing Choice 3 from the menu, and then choose to type in the command, typing in:

/usr/local/bin/eom

(use the full pathname according to where you placed the script).

Choose option 2 - In Specified Months on Specified Dates as you assign when cron should run the command.

In the screens that follow, specify:

Months: A - In ALL Months
Dates: 28, 29, 30, 31

and during the hour, and at the minutes after the hour to suit your purposes.

Enter an f at any of these screens to indicate that you have Finished specifying the selections available on that screen.

Your crontab line should look something like this when you review it:

Crony - Confirming ADDED
 
Line: Crontab Line - 002
 
0 20 28,29,30,31 * * /usr/local/bin/eom
 
Executes:
 
Month: All
 
Day of Month: 28,29,30,31
 
Day of Week: Any
 
Time: 8:00 PM
 
Edit Delete Inactivate Next Prev Quit:

Feel free to edit the command line, or whn it runs, until you are satisfied with it. Or inactivate it or delete it. Remember, nothing is final until you answer u to update cron before exiting the program. And it's not really final then, because it's easy to use Crony to manage your crontab file and make any desired changes.

As written, this works only if the value of the TZ environmental parameter is in the form of EST5EDT, where EST is the local time zone, 5 is the number of hours west (+) or east (-) of the prime meridian (Greenwich Meridian), and EDT is the local time zone, in this case indicating that daylight (summer) time is observed. But users in time zones with differing TZ specifications should be able to use the above as a guideline for creating their own script.

Basically, the script winds the hands of the clock 24 hours forward (in-so-far as the date command is concerned) and checks the date. If that date is not 1 the script exits, otherwise it executes the commands that follow later in the scripts.

We hope you enjoy using Crony...

 

User Rating: / 0
PoorBest