| Author |
Message |
Dingo

Joined: 11 Dec 2007 Posts: 1397 Location: somewhere at the end of rainbow...
|
Posted: Tue 03 Nov 2009, 13:50 Post subject:
How to indicate progress of a script reading lines? |
|
Assuming I have a shellscript performing various tasks like:
| Code: | 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
|
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 1759
|
Posted: Tue 03 Nov 2009, 14:54 Post subject:
|
|
You mean some sort of progress bar or showing the percentage of completion?
|
|
Back to top
|
|
 |
Dingo

Joined: 11 Dec 2007 Posts: 1397 Location: somewhere at the end of rainbow...
|
Posted: Tue 03 Nov 2009, 15:17 Post subject:
|
|
| 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
|
|
Back to top
|
|
 |
defpy

Joined: 24 Nov 2009 Posts: 7
|
Posted: Thu 26 Nov 2009, 09:58 Post subject:
|
|
Try something like this
| Code: | (
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 |
|
|
Back to top
|
|
 |
trapster

Joined: 28 Nov 2005 Posts: 1966 Location: Maine, USA
|
Posted: Thu 26 Nov 2009, 21:22 Post subject:
|
|
?????
_________________ trapster
Maine, USA
Asus eeepc 1005HA PU1X-BK
Frugal install:Puppeee4.31 + 1.0, Puppy4.10 + Lupu52
Currently using Puppeee-1.0 AND lupu52 w/ fluxbox
|
|
Back to top
|
|
 |
defpy

Joined: 24 Nov 2009 Posts: 7
|
Posted: Fri 27 Nov 2009, 05:55 Post subject:
|
|
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 |
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 |
I forgot zenity was not included in puppy [/code]
|
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 1759
|
Posted: Fri 27 Nov 2009, 08:28 Post subject:
|
|
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.
|
|
Back to top
|
|
 |
defpy

Joined: 24 Nov 2009 Posts: 7
|
Posted: Sun 29 Nov 2009, 03:10 Post subject:
|
|
amigo, $LINENO is very useful, thanks
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 |
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 |
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 |
|
|
Back to top
|
|
 |
|