Shell script to get the execution result of the remote server

first connect to the remote server, execute a script on the remote server, and the execution result will be saved in result.txt. There are three possible results: process failed success, wait 5 minutes if it is process, exit the entire script if it is failed, and get a compiled package from the remote server if it is success. The reason for writing the result to a file is that the script takes a long time to execute on the remote server, needs to be executed asynchronously, and serial execution takes a lot of time.
currently I search and know how to read the contents of a file from a remote server, the code is as follows:

out=$(ssh root@$source <<"EOF"
  while IFS= read -r line; do
    printf "Data : %s\n" "$line"
  done < "data.txt"
EOF
)

the above code will cycle through a file, one line at a time, but I want to read one line at a time, judge the content, and then report a grammar error if I don"t want to read it every 5 minutes.

first of all, when I run it, I will always prompt Pseudo-terminal will not be allocated because stdin is not a terminal, that I don"t know if this has any effect. In fact, through bash-x, I can see that the content of the first line in the data.txt under the remote server ~ that is / root can be obtained accurately, but out has been obtained once. How can I implement the above judgment logic I mentioned? if the content is not success and failed, wait for 5 minutes. Then if it is success, it is like a remote server to get the package, and if it is failed, it will end the execution of the native script.

Apr.05,2021

reference

-sharp!/bin/bash

IFS= && script=$(cat <<EOF
set -x
set -e
while true; do
    first_line=\$(head -n 1 /root/data.txt)
    case \$first_line in
        "process" )
            sleep 5m
            continue
            ;;

        "failed" )
            exit 1
            ;;

        "success" )
            exit 0
            ;;

        *)
            exit 2
            ;;
    esac
done
EOF
)

-sharp  scp 
if echo $script | ssh -q xx@host; then
    scp xx@host:/xx/xx/xx  xxx
fi
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38820-2c111.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38820-2c111.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?