Shell Operations

RunCommand Operation

The RunCommand operation runs a shell command on a Unix environment using whatever binary is available at /bin/sh. The environment user runs this shell command from their home directory. The Delphix Engine captures and logs all output from this command. If the script fails, the output is displayed in the Delphix Management application and command line interface (CLI) to aid in debugging.

If successful, the shell command must exit with an exit code of 0. All other exit codes will be treated as an operation failure.

Examples of RunCommand Operations

You can input the full command contents into the RunCommand operation.

remove_dir="$DIRECTORY_TO_REMOVE_ENVIRONMENT_VARIABLE"
 
if test -d "$remove_dir"; then
    rm -rf "$remove_dir" || exit 1
fi
 
exit 0

If a script already exists on the remote environment and is executable by the environment user, the RunCommand operation can execute this script directly.

/opt/app/oracle/product/10.2.0.5/db_1/dbs/myscript.sh "$ARG_ENVIRONMENT_VARIABLE" "second argument in double quotes" 'third argument in single quotes'

RunBash Operation

The RunBash operation runs a Bash command on a Unix environment using a bash binary provided by the Delphix Engine.The environment user runs this Bash command from their home directory. The Delphix Engine captures and logs all output from this command. If the script fails, the output is displayed in the Delphix Management application and command line interface (CLI) to aid in debugging.

If successful, the Bash command must exit with an exit code of 0. All other exit codes will be treated as an operation failure.

Example of RunBash Operations

You can input the full command contents into the RunBash operation.

remove_dir="$DIRECTORY_TO_REMOVE_ENVIRONMENT_VARIABLE"

# Bashisms are safe here!
if [[ -d "$remove_dir" ]]; then
    rm -rf "$remove_dir" || exit 1
fi
 
exit 0

Shell Operation Tips

Using nohup

You can use the nohup command and process backgrounding from resource in order to "detach" a process from the Delphix Engine. However, if you use nohup and process backgrounding, you MUST redirect stdout and stderr.

Unless you explicitly tell the shell to redirect  stdout and stderr in your command or script, the Delphix Engine will keep its connection to the remote environment open while the process is writing to either stdout or stderr . Redirection ensures that the Delphix Engine will see no more output and thus not block waiting for the process to finish.

For example, imagine having your RunCommand operation background a long-running Python process. Below are the bad and good ways to do this.

Bad Examples
  • nohup python file.py & # no redirection
  • nohup python file.py 2>&1 & # stdout is not redirected
  • nohup python file.py 1>/dev/null & # stderr is not redirected
  • nohup python file.py 2>/dev/null & # stdout is not redirected
Good Examples
  • nohup python file.py 1>/dev/null 2>&1 & # both stdout and stderr redirected, Delphix Engine will not block

Other Operations

RunExpect Operation

The RunExpect operation executes an Expect script on a Unix environment. The Expect utility provides a scripting language that makes it easy to automate interactions with programs which normally can only be used interactively, such as ssh. The Delphix Engine includes a platform-independent implementation of a subset of the full Expect functionality.

The script is run on the remote environment as the environment user from their home directory. The Delphix Engine captures and logs all output of the script. If the operation fails, the output is displayed in the Delphix Management application and CLI to aid in debugging.

If successful, the script must exit with an exit code of 0. All other exit codes will be treated as an operation failure.

Example of a RunExpect Operation

Start an ssh session while interactively providing the user's password.

spawn ssh user@delphix.com
expect {
    -re {Password: } {
        send "${env(PASSWORD_ENVIRONMENT_VARIABLE)}\n"
    }
    timeout {
        puts "Timed out waiting for password prompt."
        exit 1
    }
}
exit 0

SAP ASE Environment variables

Operations that run user-provided scripts have access to environment variables. For operations associated with specific dSources or virtual databases (VDBs), the Delphix Engine will always set environment variables so that the user-provided operations can use them to access the dSource or VDB.

dSource Environment Variables

Environment VariablesDescription
ASE_ENVUSEREnvironment username for the dSource
ASE_DBUSERDatabase username for the dSource
ASE_DATABASEDatabase name for the dSource
ASE_INSTANCESAP ASE Instance name for the dSource
ASE_PORTSAP ASE Instance port for the dSource

VDB Environment Variables

Environment VariablesDescription
ASE_ENVUSEREnvironment username for the VDB
ASE_DBUSERDatabase username for the VDB
ASE_DATABASEDatabase name for the VDB
ASE_INSTANCESAP ASE Instance name for the VDB
ASE_PORTSAP ASE Instance port for the VDB

Staging Server Environment Variables

Environment VariablesDescription
ASE_ENVUSEREnvironment username for the dSource
ASE_DBUSERDatabase username for the dSource
ASE_DATABASEDatabase name for the dSource
ASE_INSTANCESAP ASE Instance name for the dSource
ASE_PORTSAP ASE Instance port for the dSource
ASE_BACKUP_TYPEThis is the backup type. This is a string whose possible values are DATABASE_FULL and TRANSACTION_LOG.
ASE_BACKUP_FILE_NAMES

This is the list of the names of backup files (also known as stripes). This is a string where the stripe names are separated (not surrounded) by single quote characters. This separator was chosen because single quote characters are already disallowed from appearing in backup file names.

Here is an example to explain how this environment variable can be parsed. Suppose there are 4 stripes:

stripe 1
stripe 2
stripe 3
stripe 4

Then ASE_BACKUP_FILE_NAMES will be

stripe 1'stripe 2'stripe 3'stripe 4

In order for the customer to iterate this in a bash hook, the hook should set the value of the bash IFS (Internal Field Separator) variable to do something like the following:

IFS="'" # Need to set IFS to be a single quote character        
# in order to parse the list properly.
for file in $ASE_BACKUP_FILE_NAMES
do
    # any operations the customer wishes to perform
    echo $file >> somefile.txt
done

In this example, the contents of somefile.txt would be

stripe 1
stripe 2
stripe 3
stripe 4