Description of Shell Script Execution Results

  • Last update: March 27, 2025
  • Overview

    You can know the execution status of external tasks invoked by Shell Script in FineDataLink.

    This document also offers shell scripting suggestions.

    Logic of Judging the Shell Script Execution Status

    FineDataLink judges the script execution status based on exit codes of processes.

    • The number zero (0): indicates script execution success

    • Other exit codes: indicate script execution failure

    iconNote:

    1. If no number is returned as the exit code, the exit code is zero (0) by default, indicating script execution success.

    2. The exit command is a termination command. The entire shell script halts immediately upon encountering exit, and no subsequent commands are executed.

    Shell Scripts Containing the Exit Command

    As shown in the following figure, the script containing an exit command returns no number as the exit code (which is equal to returning zero), indicating script execution success.

    2.1-1.png

    When you run the Shell Script node in FineDataLink to execute this script, this node will be executed successfully.

    2.1-2.png

    Shell Scripts Containing No Exit Command

    The execution result of the last command in the script determines the exit code of the script.

    Take the following script as an example.

    lss

    echo 66

    The execution result is shown in the following figure. The first command fails to be executed, and the second command is executed successfully.At this time, if you use the $? command (which finds the return value of the last executed command) to obtain the exit code of the shell script, 0 will be returned, indicating script execution success, as shown in the following figure.

    2.2-1.png

    FineDataLink evaluates the shell script as successfully executed, and a message indicating successful execution is displayed in Log.

    2.2-2.png

    If you reverse the execution order of the two commands, the first command will be executed successfully, and the second command will fail to be executed, as shown in the following figure.At this time, if you use $? to obtain the exit code of the shell script, 127 is returned, indicating script execution failure, as shown in the following figure.

    2.2-2.png

    FineDataLink evaluates the execution of the entire shell script as failed.

    Recommended Scripting Method

    This document offers recommended scripting methods based on the judgment logic described in the "Logic of Judging the Shell Script Execution Status" section.

    1. You are advised to execute one task per shell script with no exit command at the end.This is to ensure that the task running log in FineDataLink always returns accurate results.

    2. If a business scenario requires executing multiple tasks using one shell script, you can use $? and set parameters to obtain the exit code of each task in the script and perform multiplication or summation to determine the script execution result.

    Execution Failure of Any Task in the Shell Script Causing Node Execution Failure

    To achieve this, you can add up the exit codes of all tasks. Once a task fails (returning a non-zero exit code), the final exit code will not be zero, in which case FineDataLink will evaluate the execution of the entire shell script as failed.

    Take the following script as an example.

    echo 666
    lss
    echo log
    ls

    You can set a parameter after each task, assign the exit code of the task to the parameter as its value (for example, obtaining the exit code of lss and assign it to the parameter as the parameter value), and add up the exit codes of all tasks at the end of the script.

    echo 666
    lss
    a=$?
    echo log
    ls
    b=$?
    exit `expr $a + $b`

    Assume that the lss task fails to be executed, as shown in the following figure.

    3.1-1.png


    At this time, if you use the echo $? command to obtain the task exit code, 127 will be returned, indicating execution failure of the entire shell script, as shown in the following figure.

    3.1-2.png

    If you run Shell Script in FineDataLink, a message indicating node execution failure will be displayed in Log, as shown in the following figure.

    3.1-3.png

    Execution Success of Any Task in the Shell Script Causing Node Execution Success

    To achieve that, you can multiply the exit codes of all tasks together.Once a task succeeds (returning zero as the exit code), the final exit code will be zero, in which case FineDataLink will evaluate the execution of the entire shell script as successful.

    You can set a parameter after each task, assign the exit code of the task to the parameter as its value (for example, obtaining the exit code of lss and assigning it to the a parameter as the parameter value), and multiply the exit codes of all tasks at the end of the script.

    echo 666
    lss
    a=$?
    echo log
    ls
    b=$?
    exit `expr $a \* $b`

    Assume that only lss fails to be executed. If you execute the script, the final exit code will be zero, indicating successful execution.

    3.2-1.png

    If you run Shell Script in FineDataLink, a message indicating successful node execution will be displayed in Log, as shown in the following figure.

    3.2-2.png

    Note: If you need detailed log, you can adjust the log level to INFO. For details, see Task Control - Task Attribute.

    附件列表


    主题: Data Development - Scheduled Task
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    9s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy