Scheduling batch files to run at prescribed times

Once created, your batch files can then be scheduled to run at prescribed times using the Windows scheduler.

Getting ready

Many geoprocessing scripts are time-intensive and best run after hours when they can take full advantage of system resources and free up your time to concentrate on other tasks. In this recipe, you will learn how to use the Windows scheduler to schedule the execution of your batch file.

How to do it...

Follow these steps to schedule a batch file with the Windows scheduler:

  1. Open the Windows scheduler by navigating to Start | All Programs | Accessories | System Tools | Control Panel | Administrative Tools. Select Task Scheduler. The scheduler should appear, as shown in the following screenshot:
    How to do it...
  2. Select the Action menu item and then Create Basic Task to display the Create Basic Task Wizard dialog box, as shown in the next screenshot.
  3. Give your task a name. In this case, we will call it List Fields from a Feature Class. Click on Next:
    How to do it...
  4. Select a trigger for when the task should be executed. This can, and often will be a time-based trigger, but there can also be other types of triggers, such as a user login or computer start. In this case, let's just select Daily. Click on Next:
    How to do it...
  5. Select a start date/time as well as a recurrence interval. In the following screenshot, I have selected the date as 12/3/2012, with the time as 1:00:00 AM, and a recurrence interval of 1 day. So, every day at 1:00 AM, this task will be executed. Click on Next:
    How to do it...
  6. Select Start a program as the action:
    How to do it...
  7. Browse to your script and add the parameters. Click on Next:
    How to do it...
  8. Click on Finish to add a task to the scheduler:
    How to do it...
  9. The tasks should now be displayed in the list of active tasks:
    How to do it...

How it works...

The Windows task scheduler keeps track of all the active tasks and handles the execution of these tasks when the prescribed trigger is fired. In this recipe, we have scheduled our task to execute each day at 1:00 AM. At this time, the batch file we created will be triggered and the arguments we specified when creating the task will be passed into the script. Using the scheduler to automatically execute geoprocessing tasks after hours, without the need for GIS staff to interact with the scripts gives you more flexibility and increases your efficiency. You might also want to consider logging the errors in your Python scripts to a log file for more information about specific problems.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset