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

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.
When you run the Shell Script node in FineDataLink to execute this script, this node will be executed successfully.
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.
FineDataLink evaluates the shell script as successfully executed, and a message indicating successful execution is displayed in Log.
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.
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 a 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.
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.
If you run Shell Script in FineDataLink, a message indicating node execution failure will be displayed in Log, as shown in the following figure.
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.
If you run Shell Script in FineDataLink, a message indicating successful node execution will be displayed in Log, as shown in the following figure.
Note: If you need detailed log, you can adjust the log level to INFO. For details, see Task Control - Task Attribute.