gnu sort --stable option не работает [дубликат]

Veo algunos problemas con el flujo del programa básico aquí. Donde tiene una construcción aquí, realmente hay un par de cosas que se están rastreando:

  1. Si algún host en su lista todavía tiene un proceso en ejecución en esta verificación, debemos registrarlo y verificar nuevamente
  2. Si el número de hosts que todavía tienen un proceso es 0, debemos salir.

Así que usaría dos bucles para este script. Además, continueno debería ser necesario aquí, y eso es probablemente lo que está causando que se repita el primer host cada vez.

Hice algunas cosas de manera diferente, principalmente probando la cantidad de PID devueltos desde psgeten lugar de verificar el código de salida ssh, y usando una sintaxis ligeramente diferente. Aquí está el ejemplo que se me ocurrió que parece funcionar para lo que quieres:

#!/bin/bash
set -eu

# get number of IPs from lines in file
NUM_IPS=$( cat ip.txt | wc -l )
echo "checking ${NUM_IPS} hosts..."

# Set number of running hosts to the max.  While arbitrary, it will 
# update to the correct number before reporting, and if it is 0 the
# while loop will exit immediately.
IPS_STILL_RUNNING=${NUM_IPS}

while [ "${IPS_STILL_RUNNING}" -gt "0" ]
do
    RUNNING_NOW=0
    for IP in $( cat ip.txt )
    do
        PROC_NUM=$( ssh ${IP} -- pgrep -f pattern | wc -l )
        if [ "${PROC_NUM}" -gt "0" ]; then
            echo "  ${IP}: still running"
            RUNNING_NOW=$(( RUNNING_NOW + 1 ))
        else
            echo "  ${IP}: not running"
        fi
    done
    echo "still running on $RUNNING_NOW hosts"
    IPS_STILL_RUNNING=${RUNNING_NOW}
    sleep 10
done
5
10.03.2019, 06:23
0 ответов

Теги

Похожие вопросы