Shell nodes support the standard shell syntax but not interactive syntax.

Background information

You can run Shell nodes only on exclusive resource groups for scheduling. For more information, see Create and use an exclusive resource group for scheduling.

A Shell node that is run on an exclusive resource group for scheduling may need to access a data source for which a whitelist is configured. In this case, you must add the required information about the resource group to the whitelist of the data source. For more information, see Create and use an exclusive resource group for scheduling.

Procedure

  1. Move the pointer over the Create icon and choose Create Node > General > Shell.
    Alternatively, you can click the name of the desired workflow in the Business Flow section, right-click General, and then choose Create Node > Shell.
  2. In the Create Node dialog box, configure the Name and Path parameters.
    Note The node name must be 1 to 128 characters in length and can contain letters, digits, underscores (_), and periods (.).
  3. Click Commit.
  4. Configure the Shell node.
    1. Write SQL statements for the Shell node.
      To use scheduling parameters for the Shell node, write the SQL statements in the following format:
      echo "$1 $2 $3"
      Note Separate multiple parameters with spaces. Example: Parameter1 Parameter2. For more information about scheduling parameters, see Overview of scheduling parameters.
    1. In the top toolbar, click the Save icon to save the SQL statements.
    2. In the top toolbar, click the Run icon to execute the SQL statements.
      If you want to use another resource group to test the Shell node on the DataStudio page, click the Run with Parameters icon in the toolbar and select the exclusive resource group that you want to use.
  5. On the configuration tab of the Shell node, click the Properties tab in the right-side navigation pane and configure scheduling properties for the node. For more information, see Configure basic properties.
  6. Save and commit the node.
    Notice You must configure the Rerun and Parent Nodes parameters on the Properties tab before you commit the node.
    1. Click the Save icon in the top toolbar to save the node.
    2. Click the Submit icon in the toolbar.
    3. In the Commit Node dialog box, configure the Change description parameter.
    4. Click OK.
    If the workspace that you use is in standard mode, you must click Deploy in the upper-right corner to deploy the node after you commit it. For more information, see Deploy nodes.
  7. Perform O&M operations on the node. For more information, see O&M overview of auto triggered nodes.
  8. Determine whether the Shell script is successfully run.
    The exit code of the Shell script determines whether the Shell script is successfully run. Exit codes:
    • 0: indicates that the Shell script is successfully run.
    • 1: indicates that the Shell script is terminated.
    • 2: indicates that the Shell script needs to be automatically rerun.
    • Other exit codes: indicate that the Shell script failed to be run.

    For a Shell script, if the first command is an invalid command, an error is returned. If a valid command is run after the invalid command, the Shell script can be successfully run. Example:

    #! /bin/bash
    curl http://xxxxx/asdasd
    echo "nihao"

    The Shell script is successfully run because the script exited as expected.

    If you change the previous script to the following script, a different result is returned. Example:

    #! /bin/bash
    curl http://xxxxx/asdasd
    if [[ $? == 0 ]];then    
        echo "curl success"
    else    
        echo "failed"    
        exit 1
    fi
    echo "nihao"

    In this case, the script fails to be run.

  9. Run an ODPS node in the Shell script.

    Command that is used to run an ODPS node:

    /opt/taobao/tbdpapp/odpswrapper/odpsconsole/bin/odpscmd   -u  {accessId}  -
    p {accesskey}   --project=xxxx   --endpoint=xxxxx   -e  "SQL statements"

    For more information about the endpoints, see Endpoints.