Set a user variable in a UNIX script

About this task

This method requires a shared filesystem. The jfd work directory must be on a shared filesystem accessible by all your jobs.

Within the script, set the values and scopes of multiple variables by specifying the files containing these variables. The jobs write to the files in the following format, with each line containing a variable-value pair:

VARIABLE1=VALUE1
VARIABLE2=VALUE2
...

Process Manager will not initially create these files — the files need to be created by the job.

For job arrays, you must append the LSB_JOBINDEX environment variable to the file names to indicate the index of each job array element.

Procedure

  1. Define a job that runs a script, or wraps the command to run within a script.
  2. Within the script, set the scope of the variable by specifying which list of variables to create, as follows:
    1. To set local variables, whose values are not available outside the scope of this flow (or subflow), from a file, use the JS_FLOW_VARIABLE_FILE environment variable to access the file.
      • To set a local variable-value pair for a job, append to the $JS_FLOW_VARIABLE_FILE file:

        echo variable=value > $JS_FLOW_VARIABLE_FILE

      • To set a local variable-value pair for a job array, append to the $JS_FLOW_VARIABLE_FILE\[$LSB_JOBINDEX\] file:

        echo variable=value>$JS_FLOW_VARIABLE_FILE\[$LSB_JOBINDEX\]
        

      The following is a sample perl script for jobs to set flow variables:

      #!/bin/perl
      $flowVarFile = $ENV{JS_FLOW_VARIABLE_FILE};
      open (OUT, ">$flowVarFile") || die "Can't open $flowVarFile: $!\n";
      print OUT "LocalVar1=value1\n";
      print OUT "LocalVar2=\"value2 with value\"\n";
      close(OUT); 
      
    2. To set global variables, whose values are available to all flows within the Process Manager Server, from a file, use the JS_GLOBAL_VARIABLE_FILE environment variable to access the file.
      • To set a global variable-value pair for a job, append to the $JS_GLOBAL_VARIABLE_FILE file:

        echo variable=value>$JS_GLOBAL_VARIABLE_FILE

      • To set a global variable-value pair for a job array, append to the $JS_GLOBAL_VARIABLE_FILE\[$LSB_JOBINDEX\] file:

        echo variable=value > $JS_GLOBAL_VARIABLE_FILE\[$LSB_JOBINDEX\]
        

      The following is a sample perl script for jobs to set global variables:

      #!/bin/perl
      $globalVarFile=$ENV{JS_GLOBAL_VARIABLE_FILE};
      open (APP, ">$globalVarFile") || die "Can't open $globalVarFile: $!\n";
      print APP "GlobalVar1=Gvalue1\n";
      print APP "GlobalVar2=\"Gvalue2 with space\"\n";
      close(APP);
      

      Process Manager sets the $JS_GLOBAL_VARIABLE_FILE environment variable to JS_HOME/work/var_comm/globalvar.job_name.

    3. To set parent flow variables, whose values are available to the scope of the parent flow for this flow (or subflow), from a file, use the JS_PARENT_FLOW_VARIABLE_FILE environment variable to access the file. If this flow is the main flow, the parent flow is also the main flow.
      • To set a parent flow variable-value pair for a job, append to the $JS_PARENT_FLOW_VARIABLE_FILE file:

        echo variable=value > $JS_PARENT_FLOW_VARIABLE_FILE

      • To set a parent flow variable-value pair for a job array, append to the $JS_GLOBAL_VARIABLE_FILE\[$LSB_JOBINDEX\] file:

        echo variable=value > $JS_PARENT_FLOW_VARIABLE_FILE\[$LSB_JOBINDEX\]
        

Results

Process Manager sets the file environment variables as follows:

  • Process Manager sets $JS_FLOW_VARIABLE_FILE to JS_HOME/work/var_comm/flowvar.job_name.

  • Process Manager sets $JS_GLOBAL_VARIABLE_FILE to JS_HOME/work/var_comm/globalvar.job_name.

  • Process Manager sets $JS_PARENT_FLOW_VARIABLE_FILE to JS_HOME/work/var_comm/parentflowvar.job_name.

Within the appropriate scope, Process Manager reads these files and records the variable-value pairs to the corresponding variable list environment variable (for example, $JS_FLOW_VARIABLE_LIST for local variables or $JS_GLOBAL_VARIABLE_LIST for global variables)