Scheduling Scripts with PAUSE and CRON

<< Click to Display Table of Contents >>

Navigation:  Robo-FTP User's Guide > Using Robo-FTP > Scheduling Script Execution >

Scheduling Scripts with PAUSE and CRON

Scheduling operations within a command script may be accomplished by using the PAUSE or CRON script commands.

 

The PAUSE command is easy to use and is best suited for simple schedules. This command suspends script execution either for a fixed period of time (e.g., 60 minutes) or until a fixed time of day (e.g., 11PM). At the designated time, the script “wakes up” and continues execution. When this command is used in a service script, it is typically at the top of an infinite loop such that execution waits for the appropriate time then continues to log in, transfer files, and log off before ultimately looping back to the PAUSE command at the top of the loop where it waits for the next designated time to run.

 

The CRON command may be used to create complex schedules. This command, like the PAUSE command, suspends script execution for a period of time and is typically used at the top of a loop. However, unlike PAUSE, the duration of the CRON command's suspension is determined by a schedule stored in an external file. You can use CRON to schedule processes “every Tuesday and Thursday at 11PM”, “once a month at midnight of the 5th day”, “every 15 minutes on March 30”, and so on. Robo-FTP includes the CronMaker scheduling utility to help you build the "crontab.txt" file that the CRON command uses for these types of schedules.

 

 

Using the CRON Command - A Brief Overview

When scheduling task(s) with CRON, there are usually three discrete components that need to be created:

 

1.One or more command scripts that perform the tasks you want done.
2.The event schedule file used by the CRON command.
3.A simple “master” script containing an infinite loop that uses the CRON command to wait for the next event and PERFORM to launch the script(s) that do the actual work.

 

Let's suppose you create a script file named "Monday.s" that transfers files to headquarters. First, you test this script works as a stand-alone script BEFORE using it in a CRON-based scheduling loop. Next you'll use the CronMaker utility to create an event schedule file named “crontab.txt” that will be used with the CRON command. You add an event named MondayHQ that sets CALL "Monday.s" as the value of the %nextcmd variable and runs weekly on Monday at 2:00 AM. Now you make a simple master CRON loop scrip that looks something like this:

 

:top

CRON ;; wait for scheduled event
PERFORM %nextcmd;; launch the task script
GOTO top;; loop to wait for next event

 

CRON is the first command in the loop so Robo-FTP evaluates your schedule file and determines the duration of the suspension. In this example, MondayHQ is the only event in the schedule so execution is suspended until next Monday morning. When the program awakens from the suspension, CALL "Monday.s" is the value stored in the %nextcmd variable so the PERFORM command in the master loop script causes your Monday.s script to run. After the Monday.s script completes its work, control returns to the master loop script where the GOTO command restarts the loop.

 

Once everything is working properly, use the Service Installer or the Enterprise Dashboard to create a Windows service that runs the master CRON loop script. Later, when you have additional automation needs, you can use the CronMaker utility to insert new events into your crontab.txt schedule. The new events may specify different event scripts to CALL with the PERFORM command and the %nextcmd variable.

 

 

Related command(s): EXIT, PAUSE, CRON, PERFORM, CALL, GOTO, RETURN