bash multi gauge

雨燕双飞 提交于 2019-12-11 08:15:51

问题


with this example

#!/bin/sh
#A gauge Box example with dialog
(
c=10
while [ $c -ne 110 ]
    do
        echo $c
        echo "###"
        echo "$c %"
        echo "###"
        ((c+=10))
        sleep 1
done
) |
dialog --title "A Test Gauge With dialog" --gauge "Please wait ...." 10 60 0

I can make a gauge.

how I can make a dialog with two o more gauges ?

similar to

[##   20% ]
[#### 40% ]

回答1:


Try --mixedgauge!

#! /bin/sh
# $Id: mixedgauge,v 1.4 2007/02/26 23:10:30 tom Exp $
: ${DIALOG=dialog}
background="An Example of --mixedgauge usage"

for i in 5 10 20 30 40 50 60 70 80 90 100
do
$DIALOG --backtitle "$background" \
        --title "Mixed gauge demonstration" \
        --mixedgauge "This is a prompt message,\nand this is the second line." \
                0 0 33 \
                "Process one"   "0" \
                "Process two"   "1" \
                "Process three" "2" \
                "Process four"  "3" \
                ""              "8" \
                "Process five"  "5" \
                "Process six"   "6" \
                "Process seven" "7" \
                "Process eight" "4" \
                "Process nine"  "-$i"
# break
sleep 1 
done

Found via https://github.com/Archivists/ltfs-console/blob/master/samples/mixedgauge




回答2:


Posting full bash script that demonstrating monitoring two background tasks as it seemed not to be easily found anywhere else.

#!/bin/bash
[ -n "$DEBUG" ] && set -x

TASK[0]=0
export TASK

task1() {
    file="/tmp/task1_progress"; echo 0 > $file
    for i in $(seq 0 10 100); do echo $i > $file; sleep 1; done
}

task2() {
    file="/tmp/task2_progress"; echo 0 > $file
    for i in $(seq 0 10 100); do echo $i > $file; sleep 2; done
}

task1 & task2 &

unset TIME_TO_FINISH PROGRESS STATUS
while /bin/true;
do
    unset TASKS
    for i in 1 2;
    do
        PROGRESS[$i]=$(cat /tmp/task${i}_progress)
        if [ ${PROGRESS[$i]} -eq 100 ];
        then
            STATUS[$i]=0
        else
            STATUS[$i]=-${PROGRESS[$i]}
        fi

        TASKS+=("Task $i" "${STATUS[$i]}")
    done

    # 0: success
    # 1: failed
    # 2: passed
    # 3: completed
    # 4: checked
    # 5: done
    # 6: skipped
    # 7: in progress
    # -X: 0-100, progress of process
    dialog \
        --title "Mixed gauge demonstration" \
        --backtitle "Backtitle" \
        --mixedgauge "This is a prompt message,\nand this is the second line." \
            0 0 $(($((${PROGRESS[1]}+${PROGRESS[2]}))/2)) \
            "${TASKS[@]}"

    I=0
    for a in 1 2; do [ ${PROGRESS[$a]} -ge 100 ] && I=$((I+1)); done

    [ $I -eq 2 ] && break
    sleep 1
done
echo waiting
wait

set +x


来源:https://stackoverflow.com/questions/12250564/bash-multi-gauge

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!