Page 1 of 1

How to indicate progress of a script reading lines?

Posted: Tue 03 Nov 2009, 17:50
by Dingo
Assuming I have a shellscript performing various tasks like:

Code: Select all

     1	#!/bin/sh
     2	# splitting
     3	pdftk doc.pdf cat 1-3 output out doc2.pdf
     4	#resizing page
     5	java -cp multivalent.jar tool.pdf.Impose -dim 1x1 -paper 6x9in doc2.pdf
     6	#renamin
     7	mv doc2.pdf doc.pdf
and so on...

and i want show progress of this script; do you think this can be done reading lines and then divide

lines read at moment/lines total

or not?

Posted: Tue 03 Nov 2009, 18:54
by amigo
You mean some sort of progress bar or showing the percentage of completion?

Posted: Tue 03 Nov 2009, 19:17
by Dingo
amigo wrote:You mean some sort of progress bar or showing the percentage of completion?
exactly, this is I mean

Posted: Thu 26 Nov 2009, 13:58
by defpy
Try something like this

Code: Select all

(
echo "15" ; sleep 1
echo "# Setting configs" ; sleep 1
echo "30" ; sleep 1
echo "# Installing software" ; sleep 1
echo "50" ; sleep 1
echo "# Additional configuration" ; sleep 1
echo "70" ; sleep 1
echo "# Removing logs" ; sleep 1
echo "100" ; sleep 1
echo "# Finished" ; sleep 1
) |
zenity --progress \
--title="Quick Setup" \
--text="Starting install..." \
--percentage=0

Posted: Fri 27 Nov 2009, 01:22
by trapster

Code: Select all

zenity
?????

Posted: Fri 27 Nov 2009, 09:55
by defpy
Script
[code]#!/bin/bash

echo "15" ; sleep 1
echo "Setting configs" ; sleep 1
echo "30" ; sleep 1
echo "Installing software" ; sleep 1
echo "50" ; sleep 1
echo "Additional configuration" ; sleep 1
echo "70" ; sleep 1
echo "Removing logs" ; sleep 1
echo "100" ; sleep 1
echo "Finished" ; sleep 1 [/code]


Runnign script with gtkdialog
[code]#!/bin/bash

export MAIN_DIALOG='
<window title="Progress" decorated="true">
<vbox>
<frame Install>
<text>
<label>Progress bar running your script</label>
</text>
<progressbar>
<label>Some Text</label>
<input>./script-test</input>
<action type="exit">Ready</action>
</progressbar>
</frame>
<hbox>
<button cancel></button>
</hbox>
</vbox>
</window>'

gtkdialog --program=MAIN_DIALOG [/code]


I forgot zenity was not included in puppy :oops: [/code]

Posted: Fri 27 Nov 2009, 12:28
by amigo
The shell 'knows' what line number it is on (echo $LINENO -I think), so you could always create a small function which would calculate a measure of progress based on (current-line / total-lines)
There is a program out there called clpbar which may do what you want. Search for it at sourceforge.

Posted: Sun 29 Nov 2009, 07:10
by defpy
amigo, $LINENO is very useful, thanks :wink:

What do you guys think about this?
[code]#!/bin/bash

script=`basename $0 `
actions=$(grep " \$perct" ${PWD}/${script}| wc -l)
perct=$(( 99 / $actions ))
now=0

now=$(( $now + $perct ))
echo $now
echo "Setting configs" ; sleep 1

now=$(( $now + $perct ))
echo $now
echo "Installing software" ; sleep 1

now=$(( $now + $perct ))
echo $now
echo "Additional configuration" ; sleep 1

now=$(( $now + $perct ))
echo $now
echo "Removing logs" ; sleep 1


now=$(( $now + $perct ))
echo $now
echo 99
echo "Finished"; sleep 1
echo 100 [/code]

or this
[code]#!/bin/bash

setting-x(){
echo "Setting configs"
}
install-x(){
echo "Installing software"
}
config-x(){
echo "Additional configuration"
}
remove-x(){
echo "Removing logs"
}
list="setting-x install-x config-x remove-x"
actions=$(echo $list | wc -w)
perct=$(( 99 / $actions ))
now=0
for item in $list;do
$item
sleep 1
now=$(( $now + $perct ))
echo $now
done
echo 99
echo "Finished"; sleep 1
echo 100[/code]

Running with gtkdialog
[code]#!/bin/bash

export MAIN_DIALOG='
<window title="Progress" decorated="true">
<vbox>
<frame Install>
<text>
<label>Progress bar running your script</label>
</text>
<progressbar>
<label>Some Text</label>
<input>./script-test</input>
<action type="exit">Ready</action>
</progressbar>
</frame>
<hbox>
<button cancel></button>
</hbox>
</vbox>
</window>'

gtkdialog --program=MAIN_DIALOG [/code]