# How to run a document generation with a scheduled task?

Using command line users can run Rational Publishing Engine automatically at a specific date/time.
We are using: RPE Command Line API, System command line and OS scheduled tasks

## On Windows:

First, we are going to create a batch file. In this file we will run a document specification and move the outputs in a different location. The name of this location will be the current date.

"C:\Program Files\IBM\Rational\Publishing Engine\1.1.1.2\launcher\rpe-launcher.exe"
- publish "C:\temp\generatedds.dsx" -noresult

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=2-4 delims=/ " %%a in ('echo %date%') do (
set YYYYMMDD=%%c%%a%%b
)

MD "C:\temp\output\report_from_!YYYYMMDD!"

COPY /V /Z "C:\temp\output\" "C:\temp\output\report_from_!YYYYMMDD!"

MOVE /Y "C:\temp\output\img" "C:\temp\output\report_from_!YYYYMMDD!"

DEL "C:\temp\output\out.html"
DEL "C:\temp\output\out.css"
DEL "C:\temp\output\out.doc"
DEL "C:\temp\output\out.pdf"
DEL "C:\temp\output\out.fo"
RD /Q "C:\temp\output\img"



In 1st line and 2nd line we are running RPE launcher with publish argument to start the publishing process with a document specification file and noresult to avoid the results dialog to be shown.
In lines 4 – 8 we create a variable that will hold the current date of the system.
In line 10 we make a folder that will be named using the date variable.
In line 12 the outputs will be copied in the folder created in line 10. You need to specify in document specification file a folder where the outputs files will be created (just to know from where you can copy the generated files) – in our case is “C:\temp\output\”.
After this we will clean the output folder (lines 16 – 21).
To schedule this bat file to be run every day do the following:
Go to Control Panel -> Scheduled Tasks.

Press Next button to select the program to run.

Figure 2: Select running program

Press Browse button to select the batch file.
Select when the file will be run.

Figure 3: When to perform the task

Press Next button, enter user’s password and finish the wizard.

Now this batch file will be runned every day and all your reports will be under C:\temp\\$current_day.

## On Linux :

Use crontab feature – which allows you to execute a specified command at set intervals. The intervals can be any valid combination of the arguments specified as the first five entries in a crontab line.

minute hour dom month dow user cmd

 minute This controls what minute of the hour the command will run on, and is between ‘0’ and ’59’ hour This controls what hour the command will run on, and is specified in the 24 hour clock, values must be between 0 and 23 (0 is midnight) dom This is the Day of Month, that you want the command run on, e.g. to run a command on the 19th of each month, the dom would be 19. month This is the month a specified command will run on, it may be specified numerically (0-12), or as the name of the month (e.g. May) dow This is the Day of Week that you want a command to be run on, it can also be numeric (0-7) or as the name of the day (e.g. sun). user This is the user who runs the command. cmd This is the command that you want run. This field may contain multiple words or spaces.

If you don’t wish to specify a value for a field, just place a * in the field.
E.g.:  30 3 * * * root cron.sh – this will run every day at 3:30 AM

For cron.sh:
crontab -e : edit your cron file
crontab -l : view your cron file
crontab -r : remove your cron file

/etc/cron.hourly/
/etc/cron.daily/
/etc/cron.weekly/

As their names suggest, executable files can be placed in any of these directories, and will be executed on an hourly, daily, or weekly basis. This saves a bit of time when setting up frequent tasks; just place the executable script in the appropriate directory and forget about it. To get the date in format YYYYMMDD in Linux use ‘date + %Y%m%d’.

### One Comments to “How to run a document generation with a scheduled task?”

1. Sam says:

Good Morning,

Thank you for your helpful post. I have followed these instructions to produce a .bat file that produces the documents I require. However I am experiencing difficulties when I attempt to schedule this as a task.

The batch file is certainly called when scheduled, and I observe in the RPE log files, the following:

22-04-2015T10:43:53:057 [RRDG_1:35-CORE] CRRPE1064I Finalizing document generation. Writing output files…

22-04-2015T10:43:53:621 [RRDG_1:35-CORE] CRRPE1064I The Microsoft Word macro RPEMacro is running.

22-04-2015T10:43:53:621 [RRDG_1:35-CORE] CRRPE3134I The command cscript “C:\Program Files (x86)\IBM\Rational\Publishing Engine\utils\word\runmacro.vbs” “C:\path\to\rpe\Output\output_file.docx” RPEMacro is running to process the Microsoft Word macro.

22-04-2015T10:43:53:645 [RRDG_1:75-SYSTEM_RUNNER_STREAMGOBBLER] Microsoft (R) Windows Script Host Version 5.8

22-04-2015T10:43:53:645 [RRDG_1:75-SYSTEM_RUNNER_STREAMGOBBLER]

22-04-2015T10:43:53:654 [RRDG_1:75-SYSTEM_RUNNER_STREAMGOBBLER] Starting Word …