Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 21 Aug 2014, 06:23
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to indicate progress of a script reading lines?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [8 Posts]  
Author Message
Dingo


Joined: 11 Dec 2007
Posts: 1415
Location: somewhere at the end of rainbow...

PostPosted: 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
View user's profile Send private message Visit poster's website 
amigo

Joined: 02 Apr 2007
Posts: 2232

PostPosted: Tue 03 Nov 2009, 14:54    Post subject:  

You mean some sort of progress bar or showing the percentage of completion?
Back to top
View user's profile Send private message 
Dingo


Joined: 11 Dec 2007
Posts: 1415
Location: somewhere at the end of rainbow...

PostPosted: 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
View user's profile Send private message Visit poster's website 
defpy


Joined: 24 Nov 2009
Posts: 7

PostPosted: 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
View user's profile Send private message 
trapster


Joined: 28 Nov 2005
Posts: 1999
Location: Maine, USA

PostPosted: Thu 26 Nov 2009, 21:22    Post subject:  

Code:
zenity

?????

_________________
trapster
Maine, USA

Asus eeepc 1005HA PU1X-BK
Frugal install: Puppeee4.31 + 1.0, Puppy4.10 + Lupu52
Currently using Slacko AND lupu52 w/ fluxbox
Back to top
View user's profile Send private message Visit poster's website 
defpy


Joined: 24 Nov 2009
Posts: 7

PostPosted: 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 Embarassed [/code]
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2232

PostPosted: 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
View user's profile Send private message 
defpy


Joined: 24 Nov 2009
Posts: 7

PostPosted: Sun 29 Nov 2009, 03:10    Post subject:  

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

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
Code:
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [8 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0739s ][ Queries: 11 (0.0035s) ][ GZIP on ]