By Patrick Kaak
In this article, we are going to show the power of file-parsing, utilizing the RES Automation Manager. Automation Manager gives us the possibility of parsing RES AM parameters and Windows variables and injecting them where needed, such as in a pre-existing script, which under normal circumstances needs to be edited every time you use it in a different scenario. As an example. we are going to use the XenApp update script, made by Thomas Koetzing, which uses some static settings in the script. The main goal is to inject all settings your normally do by hand, by using parameters and so making the script easy to import as building block in other environments, running XenApp 6.0 or 6.5.
This article only takes us through the download part. The buildingblock will however have the update-script split in two: One part to download the updates and the other to install them.
All settings are in the top of the script:
We are going to inject module parameters into these environment variables. First, import the script as resource in RES Automation Manager. To be able to parse the parameters, the script needs to imported into the database.
Add a new resource, choose ‘Stored in database’. Browse to the update script and select the script. After selecting it, go to the tab ‘properties’ and select the last two checkboxes ‘Parse variables, parameters and functions’ and ‘skip parsing of environment variables’. The last options prevents RES Automation Manager from parsing the variables used later in the script. We could update every variable in the script, but that takes to much time and will make it difficult to update the script when an updated version comes out.
After uploading and configuring the resource, go back to the first tab and choose the ‘Edit button’. Replace all the asked variables by the parameters that we are going to use in the update module. RES Automation Manager uses the following parameter structure: $[parameter]. See the screenshot below for the result:
Note: there’s currently is a minor bug in RES Automation Manager (fixed in AM2012 SR1, ed.), where double percentage ( %% ) in scripts are being replaced with a single %, so we need to work around that issue in the update script for now. Do a search and replace within the editing screen and replace all instances of %% with %%%. This results in %% after the parsing. For more info on the % issue, see RES KB article Q203306.
Also search for and remove any instances of the ‘pause’ command in the scripts, as these would hold up our auto-update module, thus needs to be removed.
As the script uses wget.exe to download all the hotfixes and Rollup packs, we also need to import wget.exe as a resource. Recommended method is to store it in the database, as it is a very small, singular executable.
After this is done, create a new module. Create a new ‘download’ task in the module. As the resources to download, select the wget.exe and the update-script. In the destination input-field, create a new parameter by right-clicking and selecting ‘Insert Parameter’->’Add Parameter’. As parameter input-options, select ‘parameter value is required (may not be empty)’. After creating the parameter, the task is ready and you can finish it with hitting ‘OK’.
The download task is now ready, but the scripts also needs to be executed. Add a new task and choose ‘Command (Execute)’. Be sure to select the checkbox ‘Execute command using Windows command interpreter’ and ‘redirect standard output and standard error to logfiles’ In the command line box, right-click and select ‘Insert Script’. Go to the script-tab, right click->’Insert Parameter’ and choose the parameter created in the download resource task. Be sure to add a backslash ‘\’ after the parameter and the scriptname behind that. See example on the right. Close the dialog with the ‘OK’ button.
Now we need to add the parameters that need to be parsed in the script. There are 3 parameters which do not need to be set by the user, as their value doesn’t need to be changed in the module. These are the XA parameter (as this is always XA), OS parameter (as it is always W2K8R2) and Download_only (as this part of the script is only going to download the hotfixes, the value is always Yes). Go to the ‘Module Parameters’ tab in the module and choose to add a new parameter. Create the XA, OS and Download_only parameters and set their corresponding values. In the ‘Input’ tab, uncheck ‘when importing buildingblock’ and ‘when scheduling job’, as the values do not need to be set by the user. When creating the parameters, be careful to use the exact same parameter name as used earlier in the script. If you make a typo or use a different name, the parameter will not be parsed!
After these 3 parameters are created, the others can be created too. Do this in the same way as the 3 first ones, but with a minor change: In the ‘input’-tab, keep the box ‘When scheduling job’ checked and Uncheck to box ‘hide parameter if parameter is not used directly’. As the parameter is used in the script, it is not used directly in the module. When this box is selected, scheduling the job would not ask for the input of these parameters resulting in an error. Unchecking this box will make sure that the parameters will be asked to the user scheduling the job.
After doing this for all needed parameters, the resulting task would be something like this on the right. The module is now ready to be scheduled on the server which is being used to download the hotfixes. I’m assuming that you have a hotfix-download directory there, that is also shared to other domain members. When scheduling the job, RES Automation Manager will ask the user for input like this:
After running the job, you will get the script output in the download directory. In this directory you will find the parsed script, the wget.exe utility, the downloaded hotfixes and rolluppacks of the XenApp version you specified. The output of the module will look similar to the screenshots shown below. Note the error-log in the module. This is normal and shows the URL’s of the Citrix hotfix KB articles:
The building block attached to this article has two scripts inside. The update script is split in to parts and two modules. The first part downloads the hotfixes on your fileserver. The second part will download all hotfixes to the local hard drive of your XenApp server and install them. As the installation of XenApp hotfixes needs UAC switched off, the script will handle that too. At the end of the job, the server is rebooted.
As I’ve hopefully illustrated with this article, parsing of script parameters with RES Automation Manager can be pretty useful. Besides inserting parameters in .cmd files, you can parse them in any text-file or script. This approach is also used in the the big Citrix buildingblock on this website, where parameters are inserted into the connection string-file (.dsn) used by the Citrix installer.