Updated on 2022-02-22 GMT+08:00

Developing a Shell Script

You can develop, debug, and run shell scripts online. The developed scripts can be run in jobs. For details, see Developing a Job.

Prerequisites

Procedure

  1. Log in to the DLF console.
  2. In the navigation tree of the Data Development console, choose Data Development > Develop Script.
  3. In the script directory list, double-click a script that you want to develop. The script development page is displayed.
  4. In the upper part of the editor, select script properties. Table 1 describes the script properties.

    Table 1 Shell script properties

    Parameter

    Description

    Example

    Host Connection

    Selects the host where a shell script is to be executed.

    -

    Parameter

    Parameter transferred to the script when the shell script is executed. Parameters are separated by spaces. For example: a b c. The parameter must be referenced by the shell script. Otherwise, the parameter is invalid.

    For example, if you enter the following shell interactive script and the interactive parameters 1, 2, and 3 correspond to begin, end, and exit, you need to enter parameters 1, 2, and 3.

    #!/bin/bash
    select ch in "begin" "end" "exit"; do
    case $ch in
    "begin")
    echo "start something" 
    ;;
    "end")
    echo "stop something" 
    ;;
    "exit")
    echo "exit" 
    break;
    ;;
    *)
    echo "Ignorant" 
    ;;
    esac

    Interactive Input

    Interactive information (passwords for example) provided during shell script execution. Interactive parameters are separated by carriage return characters. The shell script reads parameter values in sequence according to the interaction situation.

    -

  5. Edit shell statements in the editor.

    To facilitate script development, the DLF provides the script parameter function. The usage method is as follows:

    Write the script parameter name and parameter value in the shell statement. When the shell script is referenced by a job, if the parameter name configured for the job is the same as the parameter name of the shell script, the parameter value of the shell script is replaced by the parameter value of the job.

    An example is as follows:

    a=1
    echo ${a}

    In the preceding command, a indicates the parameter name. It can contain only letters, digits, hyphens (-), underscores (_), greater-than signs (>), and less-than signs (<), and can contain a maximum of 16 characters. The parameter name must be unique.

  6. In the upper part of the editor, click Execute. After executing the shell statement, view the execution history and result of the script in the lower part of the editor.
  7. Above the editor, click to save the script.

    If the script is created but not saved, set the parameters listed in Table 2.
    Table 2 Script parameters

    Parameter

    Mandatory

    Description

    Script Name

    Yes

    Name of the script. It contains a maximum of 128 characters. Only letters, digits, hyphens (-), underscores (_), and periods (.) are allowed.

    Description

    No

    Descriptive information about the script.

    Select Directory

    Yes

    Directory to which the script belongs. The root directory is selected by default.