bash多规格

时间:2012-09-03 15:23:35

标签: bash gauge

使用此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

我可以制作一个衡量标准。

如何用两个以上的仪表进行对话?

类似于

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

2 个答案:

答案 0 :(得分:3)

试试--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

通过https://github.com/Archivists/ltfs-console/blob/master/samples/mixedgauge

找到

答案 1 :(得分:1)

发布完整的bash脚本,演示监控两个后台任务,因为它似乎不容易在其他任何地方找到。

#!/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