Shell Script Execution Functions(3.1)

The scriptExec function runs a shell script on the EC where the workflow runs and then returns a UDR that contains the exit value. The mzadmin user must have execute permissions on the specified script file.

ScriptResult scriptExec
 ( string path,
 string argument [,...]) //Optional
ParameterDescription

path

The absolute path of the script. When the directory is set in the path variable of the mzadmin user on the host, only the filename is required.

argumentCommand line argument(s). The total size of the arguments must not exceed 50kB.

Returns

A ScriptResult UDR containing the following fields:

  • ExitValue (int) - The return code from the shell script.
  • MZError (string) - Error description from   (if any).
  • OriginalData (bytearray) - This field is always empty.
  • StdError (string) - Script output on StdError.
  • StdOut (string) - Script output on StdOut.
  • hasMZError (boolean) - True if script failed to execute, otherwise false.

Note!

When the output to stdout or stderr is large, the execution of the script may terminate before the data is fully streamed. This will interrupt the streams and result in partial outputs in the ScriptResult UDR.  You may add one more sleep periods in the script to ensure that the output is complete before the execution is terminated.

Example - Using scriptExec

initialize {
    ScriptResult rc;
    rc = scriptExec("/home/mzadmin/scripts/script1.sh", "arg1","arg2");    
    debug("rc= "+ rc);   
}
consume {    
    udrRoute(input);
}

Substrings separated by spaces are interpreted as separate arguments by the scriptExec function. If the arguments contain spaces you may substitute these in your APL code and in the script.

Example - Substituting spaces

Substitute underscores in arguments with spaces in bash script:

for ARG in $* 
do	
	echo ${ARG//_/ }
done

Substitute spaces in arguments with underscore in APL:

initialize {
    ScriptResult rc;
    rc = scriptExec("/home/mzadmin/scripts/script1.sh", "This_argument_contains_spaces");    
    debug(rc.StdOut);   
}

Output:

This argument contains spaces