Return variable/status/value from nt/windows job - similar to sql return variables/status
search cancel

Return variable/status/value from nt/windows job - similar to sql return variables/status

book

Article ID: 254741

calendar_today

Updated On:

Products

CA Workload Automation DE - Business Agents (dSeries)

Issue/Introduction

We are trying to get the return code/value/status from a windows/nt job. Similar to sql stored procedure or other jobs listed on your docs here:

 

In this case, we're using a powershell command. Example: 

  • Command to run: powershell.exe
  • Arguments to pass: return (Get-Content "D:\path\to\data\file.txt" | Select -First 3 | Select -Last 1).Substring(12,10)

 

The output of the command can be seen in the spool - so we know it is running as expected. However, how to we get this into a variable so that they can be used by subsequent jobs? 

 

 

Environment

Release : 12.1

 

Cause

Windows and Unix jobs do not offer a way to return the STDOUT/output to a variable that can be used in subsequent jobs. 

 

Resolution

At this time there are three options (documented below). An enhancement idea/request has also been created. You can find and vote for it here: Get output variable(s)/value(s) from windows/unix jobs similar to stored procedure output variables.

 

Option 1:

Use the Text File Reading and Monitoring job and WOB._lstatus to return the line/data. 

Example: 

  1. Define an Alert as follows:
    • setVar('status',WOB._lstatus);
    • setVar('symstatus',APPL.status);
  2. Run the Windows (or Unix) job that generates the output. Example:
    Command: powershell.exe
    Arguments: -Command & {Write-Host "This is a test `r`nThis isnt a test"}
    Note: If the command generates the output to stdout then configure the Environment Variables with a variable:
    • Name: STDOUT
    • Value: Path_to_file
  3. Configure the Text File Reading and Monitoring Job to search the file for the data you want. 
    Other Monitor Parameters: Return immediately
    Notifications: 
    1. Deselect "Use Application-level defaults"
    2. Create a New Alert with Monitor State "Complete" selected. Select the Alert from step 1 in the "Alert name" drop down. 
  4. In the next job where you want to use this information, use the following javascript to access/utilize the data: 
    APPL.status1=getVar('status');
    var temp= APPL.status1.split(":");
    var value=temp[1];

 

Based on the above, you can then use %APPL.status1 or %value to access the information picked up from the Text File Reading and Monitoring Job. 

 

 

Option 2:

Write the output of the Windows job to a network drive that the DSeries server can access via javascript. 

Con: Need to have a shared drive location to temporarily store the output data.

 

Example: 

  1. Run the Windows (or Unix) job that generates the output (and stdout output file in this case). Example:
    Command: powershell.exe
    Arguments: (Get-Content "D:\path\to\data\file.txt" | Select -First 3 | Select -Last 1).Substring(12,10) | Out-File -filepath "\\unc|nfs\path\to\output_file.txt" -Encoding utf8
  2. Then, in the next action, read using the output file of action 1 - using the following javascript:
    if (file_exist('/unc|nfs/path/to/output_file.txt'))
    {
       APPL.lineCount = file_getLineCount('/unc|nfs/path/to/output_file.txt');
    }
    if (APPL.lineCount != 0)
    {
       APPL.filedatelines = file_readLines('/unc|nfs/path/to/output_file.txt',0,1);
       APPL.filedate = APPL.filedatelines[0];
    }
  3. This makes the js variable APPL.filedate populated that can be used by subsequent jobs. 

 

Option 3:

Use the server cli to setvar to redirect output (via an environment variable) to a Global Variable. Then, use the value in the Global Variable. 

Con: The cli component would need to be installed on each agent where this needs to be done. 

Example: 

  1. Run the Unix (or Windows) job that generates the output. Example:
    Command: /bin/bash
    Arguments: -c "tail -n1 /opt/wade123/de/deserver/logs/tracelog.txt | cut -d' ' -f1-2"
    Environment Variables: Name: STDOUT, Value: /tmp/s3job

  2. Run the Unix (or Windows) job that calls the cli to use setvar. Example: 
    Command: /opt/wade123/de/deserver/bin/cli 
    Arguments: <name of your wade server> 7500 <user> <pass> 'setvar name("s3var") value("'$(cat /tmp/s3job)'")'

  3. Run the Unix (or Windows) job that uses the global variable. Example: 
    Javascript: APPL.mys3var=getVar('S3VAR','DEFAULT');
    Command: /bin/bash
    Arguments: APPL.mys3var=getVar('S3VAR','DEFAULT');