How to indicate progress of a script reading lines?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Dingo
Posts: 1437
Joined: Tue 11 Dec 2007, 17:48
Location: somewhere at the end of rainbow...
Contact:

How to indicate progress of a script reading lines?

#1 Post 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?
replace .co.cc with .info to get access to stuff I posted in forum
dropbox 2GB free
OpenOffice for Puppy Linux

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#2 Post by amigo »

You mean some sort of progress bar or showing the percentage of completion?

User avatar
Dingo
Posts: 1437
Joined: Tue 11 Dec 2007, 17:48
Location: somewhere at the end of rainbow...
Contact:

#3 Post by Dingo »

amigo wrote:You mean some sort of progress bar or showing the percentage of completion?
exactly, this is I mean
replace .co.cc with .info to get access to stuff I posted in forum
dropbox 2GB free
OpenOffice for Puppy Linux

User avatar
defpy
Posts: 7
Joined: Tue 24 Nov 2009, 12:50

#4 Post 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

User avatar
trapster
Posts: 2117
Joined: Mon 28 Nov 2005, 23:14
Location: Maine, USA
Contact:

#5 Post by trapster »

Code: Select all

zenity
?????
trapster
Maine, USA

Asus eeepc 1005HA PU1X-BK
Frugal install: Slacko
Currently using full install: DebianDog

User avatar
defpy
Posts: 7
Joined: Tue 24 Nov 2009, 12:50

#6 Post 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]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#7 Post 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.

User avatar
defpy
Posts: 7
Joined: Tue 24 Nov 2009, 12:50

#8 Post 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]

Post Reply