Menu Bash da tela -ls dados

1

Dados da tela

There are screens on:
    27454.world-of-dragons_SERVER   (07/05/2018 04:38:56 PM)        (Attached)
    6223.potato-wod_SERVER  (07/05/2018 10:16:12 AM)        (Attached)
    1681.potato-wod_MASTER  (07/04/2018 10:06:20 PM)        (Detached)
    30448.world-of-dragons_MASTER   (07/04/2018 09:06:01 PM)        (Detached)
4 Sockets in /var/run/screen/S-kreezxil.

Eu criei um script que gera um menu para os consoles Detached.

#!/bin/bash
IDX=0
declare -a pids
declare -a names

for f in $(screen -ls); do
    if [[ $f = *"MASTER"* ]]; then
            IFS="." read -r -a data <<< "$f"
            pids[IDX]="${data[0]}"
            IFS="_" read -r -a name <<< "${data[1]}"
            names[IDX]="${name[0]}"
            ((++IDX))
    fi
done

size=${#pids[@]}

while true; do
    clear
    printf '\nSCREEN\tPID\tNAME\n'

    for (( i=0; i<${size}; i++ )); do
            printf '%s\t%s\t%s\n' ${i} ${pids[i]}  ${names[i]}
    done

    printf '\nWhich screen # would you like to resume?\nEnter to q to quit or exit\n'
    read n

    if [ $n == 'q' ]; then
            exit
    fi

    if [ $n -lt 0 || $n -gt $size ]; then
            read -p "Invalid Option: Press [Enter] to try again" readEnterkey
            continue
    fi

    screen -r ${pids[$n]}
done

Pode selecionar ser usado para tornar o script mais elegante, se sim, como? (esta é uma questão primordial)

Nota: desejo manter a legibilidade do script. Sugestões: congratulou-se com.

    
por Kreezxil 05.07.2018 / 21:25

0 respostas