¿Procesos paralelos en el monitor bash bitcoin que registra los datos de fuga sql?

Escribí un programa bash para monitorear dispositivos de minería de bitcoin, funcionó fantásticamente ejecutando un conjunto de bucles por segundo hasta que superé las 8 unidades que se monitorearon. Mi solución fue integrar el procesamiento en paralelo que parece haber causado más problemas de los que solucionó, lo que parece que obtengo ahora es que todos mis datos se registrarán desde una sola unidad o el programa producirá un error debido a las variables I Estoy grabando apareciendo vacío. primero publicaré mi script original con toda la información personal eliminada y luego publicaré mi intento de procesamiento paralelo para ver si alguien tiene una solución. Gracias por tu ayuda.

#!/bin/bash
# RPC the summary data
ti2=0
t=1 #Time Between Scans In Seconds
zero() {
SUMMAC=0
SUMMRJ=0
SUMMUT=0
GHs=0
SUMMHS=0
SUMMGW=0
SUMMRF=0
SUMMLW=0
SUMMDW=0
SUMMFB=0
SUMMHW=0
SUMMNB=0
SUMMET=0
}
id=(`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
go
SELECT COUNT(*) FROM Mining_Rigs
go
quit
EOF`)
for (( c=0; c<=$id-1; c++ ))
do
IPI=`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
SELECT IP_Address FROM Mining_Rigs where Row = $c
go
quit
EOF`
IP[$c]=$IPI
IPI=`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
SELECT Port FROM Mining_Rigs Where Row = $c
go
quit
EOF`
Port[$c]=$IPI
IPI=`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
SELECT Name FROM Mining_Rigs where Row = $c
go
quit
EOF`
Name[$c]=$IPI
IPI=(`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
SELECT Active FROM Mining_Rigs where Row = $c
go
quit
EOF`)
Active[$c]=$IPI
if [ ${Active[$c]} -eq 1 ]; then
l_TELNET=`echo "quit" | telnet ${IP[$c]} ${Port[$c]} | grep "Escape character is"`
if [ "$?" -ne 0 ]; then
  echo "Connection to ${IP[$c]} on port ${Port[$c]} failed"
  echo "${Name[$c]} Will Be Made Inactive Until Service Is Reloaded"
  sleep 2
  tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
UPDATE Mining_Rigs SET Active = 0 WHERE Row = $c
go
quit
EOF
Active[$c]=0
fi
fi
done
ti=$(date +%s)
while :
do
DOY=$(date +%s)
for (( c=0; c<=$id-1; c++ ))
do
if [ ${Active[$c]} -eq 1 ]; then
echo "{\"command\":\"summary\"}" | nc ${IP[$c]} ${Port[$c]} | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > sum.txt
for NODE in "${IP[$c]}"; do

    while read cline ; do
        #DEBUGGING=$(echo $cline | awk '{ print "1="$1, "2="$2, "3="$3; exit; }' | sed 's/[:,\"]//g' )
    #echo "$NODE: $DEBUGGING"
        FLD1=$(echo $cline | awk '{ print $1; exit; }' | sed 's/[:,\"]//g' )
        #
    if [ "$FLD1" == "Getworks" ] ; then
            SUMMGW=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g')
        elif [ "$FLD1" == "Accepted" ] ; then
            SUMMAC=$(echo $cline | awk '{ printf($2); echo ; exit; }' | sed 's/[:,\"]//g')
        elif [ "$FLD1" == "Rejected" ] ; then
            SUMMRJ=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g')
        elif [ "$FLD1" == "Remote" ] ; then
            SUMMRF=$(echo $cline | awk '{  printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Utility" ] ; then
            SUMMUT=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "MHS" ] ; then
            SUMMHS=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Local" ] ; then
            SUMMLW=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Discarded" ] ; then
            SUMMDW=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Found" ] ; then
            SUMMFB=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Hardware" ] ; then
            SUMMHW=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Network" ] ; then
            SUMMNB=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Elapsed" ] ; then
            SUMMET=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g' )
       fi
    done < sum.txt
if [ $(echo "scale=0; ($SUMMHS) / 1" | bc) -gt 0 ]; then
GHs=$(echo "scale=9; ($SUMMHS) / 1000" | bc)
fi
if [ $DOY -gt $ti ]; then
midate=`date -d "UTC 1970-01-01 $ti secs" "+%Y-%m-%d %H:%M:%S"`
tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
insert into "${Name[$c]}" (Date,Node,Accepted,Rejected,Utility,GHs,Getworks,Remfail,Local,Discard,Found,Hwerr,Network,Uptime) values( '$midate','$NODE','$SUMMAC','$SUMMRJ','$SUMMUT','$GHs','$SUMMGW','$SUMMRF','$SUMMLW','$SUMMDW','$SUMMFB','$SUMMHW','$SUMMNB','$SUMMET');
go
quit
EOF
zero
ti2=1
elif [ $DOY -eq $ti ]; then
midate=`date -d "UTC 1970-01-01 $DOY secs" "+%Y-%m-%d %H:%M:%S"`
tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
insert into "${Name[$c]}" (Date,Node,Accepted,Rejected,Utility,GHs,Getworks,Remfail,Local,Discard,Found,Hwerr,Network,Uptime) values( '$midate','$NODE','$SUMMAC','$SUMMRJ','$SUMMUT','$GHs','$SUMMGW','$SUMMRF','$SUMMLW','$SUMMDW','$SUMMFB','$SUMMHW','$SUMMNB','$SUMMET');
go 
quit
EOF
zero
ti2=0
else
tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
insert into "${Name[$c]}" (Date,Node,Accepted,Rejected,Utility,GHs,Getworks,Remfail,Local,Discard,Found,Hwerr,Network,Uptime) values( FROM_UNIXTIME('$DOY') ,'$NODE','$SUMMAC','$SUMMRJ','$SUMMUT','$GHs','$SUMMGW','$SUMMRF','$SUMMLW','$SUMMDW','$SUMMFB','$SUMMHW','$SUMMNB','$SUMMET');
EOF
zero
fi
done
fi
done
if [ $ti2 -eq 1 ]; then
ti3=$(expr $DOY - $ti )
t2=$(expr $t - $ti3 )
if [ $t2 -ge 0 ]; then
ti=$(expr $DOY + $t2 )
sleep $t2
fi
elif [ $ti2 -eq 0 ]; then
ti=$(expr $DOY + $t )
sleep $t
fi
done

este es mi programa original funcionó de maravilla hasta que supere las 8 unidades, el siguiente es mi intento de procesamiento paralelo

#!/bin/bash
# RPC the summary data
ti2=0
t=3 #Time Between Scans In Seconds
Json() {
zero() {
SUMMAC=0
SUMMRJ=0
SUMMUT=0
GHs=0
SUMMHS=0
SUMMGW=0
SUMMRF=0
SUMMLW=0
SUMMDW=0
SUMMFB=0
SUMMHW=0
SUMMNB=0
SUMMET=0
}
c=$d
if [ ${Active[$c]} -eq 1 ]; then
echo "{\"command\":\"summary\"}" | nc -w 1 ${IP[$c]} ${Port[$c]} | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > sum.txt
for NODE in "${IP[$c]}"; do

    while read cline ; do
        #DEBUGGING=$(echo $cline | awk '{ print "1="$1, "2="$2, "3="$3; exit; }' | sed 's/[:,\"]//g' )
        #echo "$NODE: $DEBUGGING"
        FLD1=$(echo $cline | awk '{ print $1; exit; }' | sed 's/[:,\"]//g' )
        #
    if [ "$FLD1" == "Getworks" ] ; then
            SUMMGW=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g')
        elif [ "$FLD1" == "Accepted" ] ; then
            SUMMAC=$(echo $cline | awk '{ printf($2); echo ; exit; }' | sed 's/[:,\"]//g')
        elif [ "$FLD1" == "Rejected" ] ; then
            SUMMRJ=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g')
        elif [ "$FLD1" == "Remote" ] ; then
            SUMMRF=$(echo $cline | awk '{  printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Utility" ] ; then
            SUMMUT=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "MHS" ] ; then
            SUMMHS=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Local" ] ; then
            SUMMLW=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Discarded" ] ; then
            SUMMDW=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Found" ] ; then
            SUMMFB=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Hardware" ] ; then
            SUMMHW=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Network" ] ; then
            SUMMNB=$(echo $cline | awk '{ printf($3); exit; }' | sed 's/[:,\"]//g' )
        elif [ "$FLD1" == "Elapsed" ] ; then
            SUMMET=$(echo $cline | awk '{ printf($2); exit; }' | sed 's/[:,\"]//g' )
       fi
    done < sum.txt
    echo $SUMMHS
    echo $SUMMUT
    if [ $(echo "scale=0; ($SUMMHS) / 1" | bc) -gt 0 ]; then
GHs=$(echo "scale=9; ($SUMMHS) / 1000" | bc)
fi
if [ $DOY -gt $ti ]; then
midate=`date -d "UTC 1970-01-01 $ti secs" "+%Y-%m-%d %H:%M:%S"`
zero
ti2=1
elif [ $DOY -eq $ti ]; then
midate=`date -d "UTC 1970-01-01 $DOY secs" "+%Y-%m-%d %H:%M:%S"`
tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
insert into "${Name[$c]}" (Date,Node,Accepted,Rejected,Utility,GHs,Getworks,Remfail,Local,Discard,Found,Hwerr,Network,Uptime) values( '$midate','$NODE','$SUMMAC','$SUMMRJ','$SUMMUT','$GHs','$SUMMGW','$SUMMRF','$SUMMLW','$SUMMDW','$SUMMFB','$SUMMHW','$SUMMNB','$SUMMET');
go 
quit
EOF
zero
ti2=0
else
tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
insert into "${Name[$c]}" (Date,Node,Accepted,Rejected,Utility,GHs,Getworks,Remfail,Local,Discard,Found,Hwerr,Network,Uptime) values( FROM_UNIXTIME('$DOY') ,'$NODE','$SUMMAC','$SUMMRJ','$SUMMUT','$GHs','$SUMMGW','$SUMMRF','$SUMMLW','$SUMMDW','$SUMMFB','$SUMMHW','$SUMMNB','$SUMMET');
EOF
zero
fi
done
fi
    }
id=(`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
go
SELECT COUNT(*) FROM Mining_Rigs
go
quit
EOF`)
for (( c=0; c<=$id-1; c++ ))
do
IPI=`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
SELECT IP_Address FROM Mining_Rigs where Row = $c
go
quit
EOF`
IP[$c]=$IPI
IPI=`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
SELECT Port FROM Mining_Rigs Where Row = $c
go
quit
EOF`
Port[$c]=$IPI
IPI=`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
SELECT Name FROM Mining_Rigs where Row = $c
go
quit
EOF`
Name[$c]=$IPI
IPI=(`tsql -S 192.168.0.1\\MSSQLSERVER -U Username -P Password -o qh <<EOF
use DATABASE NAME
SELECT Active FROM Mining_Rigs where Row = $c
go
quit
EOF`)
Active[$c]=$IPI
done
ti=$(date +%s)
Getinfo
while :
do
DOY=$(date +%s)
for (( c=0; c<=$id-1; c++ ))
do
Json $c &
echo $c
done
if [ $ti2 -eq 1 ]; then
ti3=$(expr $DOY - $ti )
t2=$(expr $t - $ti3 )
if [ $t2 -ge 0 ]; then
ti=$(expr $DOY + $t2 )
sleep $t2
fi
elif [ $ti2 -eq 0 ]; then
ti=$(expr $DOY + $t )
sleep $t
fi
wait
done

Respuestas a la pregunta(1)

Su respuesta a la pregunta