You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 18 Next »

Setting user defined parameters in shell scripts

  • Environment variables are used to make job and order parameters accessible to shell scripts.
  • Environment variables are named using a predefined prefix and the name of the original parameter: 
    • The default value for the environment variable prefix is SCHEDULER_PARAM_
    • For example, the job parameter param1 is can be accessed by the environment variable SCHEDULER_PARAM_PARAM1 .
    • Environment variables are used with uppercase letters.
    • If the SCHEDULER_PARAM_ prefix is not to be used for the environment variables and instead the parameter names themselves then the following setting can be added to the ./config/scheduler.xml file:

      <params>
          <param name="scheduler.variable_name_prefix" value="*NONE"/>
          ...
      </param>

      (info) Note that: there is a risk of JobScheduler overwriting already existing environment variables with new ones of the same name that have been derived from job or order parameters if a prefix such as SCHEDULER_PARAM_ is not used.

Examples

Example for Windows
 <job>
    <params>
        <param name="param1"  value="Test"/>
    </params>
    <script language="shell">
        <![CDATA[
 rem This is an example shell script to show the use of parameters
 echo Param1 has the value %SCHEDULER_PARAM_PARAM1%
        ]]>
    </script>
    <run_time/>
 </job>
Example for Unix
 <job>
    <params>
        <param name="param1" value="Test"/>
    </params>
    <script language="shell">
        <![CDATA[
 # This is an example shell script to show the use of parameters
 echo "Param1 has the value $SCHEDULER_PARAM_PARAM1"
        ]]>
    </script>
    <run_time/>
 </job

 

If you want to use parameters as command line arguments for a script then just add the environment variables as arguments in the command line:

Example for command line (Unix)
  anyshellscript.sh $SCHEDULER_PARAM_PARAM1 $SCHEDULER_PARAM_PARM2 ...

Passing parameters to subsequent shell jobs in a job chain

  • With every change of status in job chains JobScheduler parses a temporary file for name=value pairs. 
    • The name of the temporary file is available with the environment variable SCHEDULER_RETURN_VALUES
    • The name/value pairs are automatically added as order parameters

.

Example for First Job
 <job order="yes"
     stop_on_error="no">
    <params>
        <param name="param1"  value="Test"/>
    </params>
    <script language="shell">
        <![CDATA[
 rem This is an example shell script to demonstrate the use of parameters 
 echo newParam=an example value >> %SCHEDULER_RETURN_VALUES%
        ]]>
    </script>
    <run_time/>
 </job>
Example for Second Job
 <job order="yes">
    <params>
        <param name="param1" value="Test"/>
    </params>
    <script language="shell">
        <![CDATA[
 echo newParam has the value %SCHEDULER_PARAM_NEWPARAM%
        ]]>
    </script>
    <run_time/>
 </job>
Example for Job Chain
 <job_chain>
    <job_chain_node state="100"
                    job="job_sample_shell_with_parameter"
                    next_state="200"
                    error_state="error"/>
    <job_chain_node state="200"
                    job="job_sample_shell"
                    next_state="success"
                    error_state="error"/>
    <job_chain_node state="success"/>
    <job_chain_node state="error"/>
 </job_chain>

Related Downloads

 

  • No labels