问题描述
该脚本的 run_tasks.bash 阅读文本文件
该脚本需要逐行读取文本文件,并在文本文件中执行脚本
有关file.txt的一个重要备注
在txt文件的行号可能会有所不同
例如在TXT文件中的第一个运行线路可能是12
在在TXT文件中的第二个运行线可能是213为例,等等.....
./run_tasks.bash /tmp/file.txt
文本文件的例子 - file.txt的
1 /tmp/run.sh
2 /var/tmp/load_run.pl
3 /etc/RT/LM.pl
。
。
我想要做的是一个进程对话框进度,说明在txt文件的任务数
例如,如果任务(系)中的TXT文件号为34
然后对话过程将根据34任务开始从0%到100%的
或者
如果任务在TXT(行)的数目是321,然后对话过程中会从0%到100%的参考321任务启动
另一件事对话框需要查看每个破坏脚本的对话框中
请指教如何根据我的要求建立的对话框code
平均值,而我有以下的对话框code 但我不知道如何去迎合code到不同的任务中的TXT文件(行)
#!/ bin / sh的
衡量#A与对话框的例子
(
C = 10
而[$ C -ne 110]
做
回声$ C
回声###
回声$ C%
回声###
((C + = 10))
睡眠1
DONE
)|
对话框--title的检验压力表对话框--gauge请稍候......10 60 0
这是数学的问题;)在项目
我已经把总项目数你马上就处理。你可能想有一些像项目= $(WC -l file.txt的)
那里。要处理的行数转换成一个百分比,我 $(($处理* 100 / $项目))
。注意顺序,因为我们只有整数通常的处理/项目* 100将无法工作。
#!/斌/庆典(
项目= 123
处理= 0
而[$处理-le $项目];做
PCT = $(($处理* 100 / $项目))
回声XXX
回声处理项目$处理
回声XXX
回声$ PCT
加工= $((处理+ 1))
睡0.1
DONE
)|对话框--title量表--gauge请等待......10 60 0
The script run_tasks.bash read the text file
The script need to read line by line the text file and execute the scripts in the text file
One important remark about file.txt
Lines numbers in the txt file could be different
For example on the first running lines in txt file could be 12
On the second running lines in txt file could be for example 213 , and so on .....
./run_tasks.bash /tmp/file.txt
Example of text file - file.txt
1 /tmp/run.sh
2 /var/tmp/load_run.pl
3 /etc/RT/LM.pl
.
.
What I want to do is a process dialog progress that illustrate the number of the tasks in the txt file
For example if number of tasks ( lines ) in the txt file is 34Then the dialog process will start from 0% to 100% according to the 34 tasks
Or
If the number of tasks (lines) in the txt are 321 then the dialog process will start from 0% to 100% reference to the 321 tasks
Another thing the dialog need to view each of the ruining script in the dialog
Please advice how to build the dialog code according to my requirements
Mean while I have the following dialog code but I not understand how to fit this code to the different tasks ( lines ) in the txt file
#!/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
It's a matter of math ;) In items
I've put the total number of items you'll be processing. You probably want to have something like items=$(wc -l file.txt)
there. To convert the number of processed lines into a percentage, I do $(( $processed * 100 / $items))
. Note the order, since we only have integers the usual processed/items*100 won't work.
#!/bin/bash
(
items=123
processed=0
while [ $processed -le $items ]; do
pct=$(( $processed * 100 / $items ))
echo "XXX"
echo "Processing item $processed"
echo "XXX"
echo "$pct"
processed=$((processed+1))
sleep 0.1
done
) | dialog --title "Gauge" --gauge "Wait please..." 10 60 0
这篇关于在Linux机器上的bash +进度对话栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!