From: Bit Twister on 2 Jun 2010 02:20 On Tue, 1 Jun 2010 21:49:37 -0700 (PDT), srikanth wrote: > Just i need a progress bar some thing like 'Browsing URLs...' here the > dots should show the progress bar. > some thing like . . . again it should start . . . > I think you understood my question? So how can i implement this > technique in my script? Here save/run this script. #!/bin/bash _wheel="|/-\\" _c=0 _counter=0 printf "Browsing URLs." for i in {1..100} ; do printf "\010%s" ${_wheel:$_c:1} let _c="_c + 1" if [ $_c -gt 3 ] ; then _c=0 fi let _counter="_counter + 1" if [ $_counter -gt 10 ] ; then _counter=0 printf "\010.|" fi ls -al /usr/* > /dev/null done printf "\n"
From: Chris F.A. Johnson on 2 Jun 2010 04:41 On 2010-06-02, Bit Twister wrote: > On Tue, 1 Jun 2010 21:49:37 -0700 (PDT), srikanth wrote: > >> Just i need a progress bar some thing like 'Browsing URLs...' here the >> dots should show the progress bar. >> some thing like . . . again it should start . . . >> I think you understood my question? So how can i implement this >> technique in my script? > > Here save/run this script. > #!/bin/bash > _wheel="|/-\\" > _c=0 > _counter=0 > printf "Browsing URLs." > for i in {1..100} ; do > printf "\010%s" ${_wheel:$_c:1} > let _c="_c + 1" > if [ $_c -gt 3 ] ; then > _c=0 > fi > > let _counter="_counter + 1" > if [ $_counter -gt 10 ] ; then > _counter=0 > printf "\010.|" > fi > ls -al /usr/* > /dev/null > done > printf "\n" Or, in a syntax that will work in *any* posix shell (including bash): sleep 5 & pid=$! delay=.25 spinner='|/-\' while : do temp=${spinner#?} printf " %c\r" "$spinner" spinner=$temp${spinner%"$temp"} sleep $delay ## requires sleep that accepts decimals done & wait $pid && kill $! -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== ===== and is released under the GNU General Public Licence =====
From: srikanth on 7 Jun 2010 11:37 On Jun 2, 1:41 pm, "Chris F.A. Johnson" <cfajohn...(a)gmail.com> wrote: > On 2010-06-02, Bit Twister wrote: > > > > > On Tue, 1 Jun 2010 21:49:37 -0700 (PDT), srikanth wrote: > > >> Just i need a progress bar some thing like 'Browsing URLs...' here the > >> dots should show the progress bar. > >> some thing like . . . again it should start . . . > >> I think you understood my question? So how can i implement this > >> technique in my script? > > > Here save/run this script. > > #!/bin/bash > > _wheel="|/-\\" > > _c=0 > > _counter=0 > > printf "Browsing URLs." > > for i in {1..100} ; do > > printf "\010%s" ${_wheel:$_c:1} > > let _c="_c + 1" > > if [ $_c -gt 3 ] ; then > > _c=0 > > fi > > > let _counter="_counter + 1" > > if [ $_counter -gt 10 ] ; then > > _counter=0 > > printf "\010.|" > > fi > > ls -al /usr/* > /dev/null > > done > > printf "\n" > > Or, in a syntax that will work in *any* posix shell (including > bash): > > sleep 5 & > pid=$! > > delay=.25 > spinner='|/-\' > while : > do > temp=${spinner#?} > printf " %c\r" "$spinner" > spinner=$temp${spinner%"$temp"} > sleep $delay ## requires sleep that accepts decimals > done & > wait $pid && kill $! > > -- > Chris F.A. Johnson, author <http://shell.cfajohnson.com/> > =================================================================== > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) > Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress) > ===== My code in this post, if any, assumes the POSIX locale ===== > ===== and is released under the GNU General Public Licence ===== How can i implement this script into my script? sorry for asking these type of questions as i am poor at coding.
From: Bit Twister on 7 Jun 2010 12:11 On Mon, 7 Jun 2010 08:37:03 -0700 (PDT), srikanth wrote: > How can i implement this script into my script? sorry for asking these > type of questions as i am poor at coding. Just an FYI. Chris's script is executed as a child/sub-process. Downside to that is your main code can hang reading a site and Chris's spinner will still be spinning away. My script was using a for loop to emulate your loop of reading sites. My ls > /dev/null was a replacement of your fetching/processing web site contents and allow you to see the spinner/wheel actually spinning.
From: srikanth on 8 Jun 2010 05:14
On Jun 7, 9:11 pm, Bit Twister <BitTwis...(a)mouse-potato.com> wrote: > On Mon, 7 Jun 2010 08:37:03 -0700 (PDT), srikanth wrote: > > How can i implement this script into my script? sorry for asking these > > type of questions as i am poor at coding. > > Just an FYI. Chris's script is executed as a child/sub-process. > > Downside to that is your main code can hang reading a site and Chris's > spinner will still be spinning away. > > My script was using a for loop to emulate your loop of reading sites. > My ls > /dev/null was a replacement of your fetching/processing web > site contents and allow you to see the spinner/wheel actually spinning. I have tried by placing another for loop in my script. It keeps on failing. Here is the script #!/bin/bash if [ -z "$1" ] then printf "Provide the text file location to process.\n" exit 0 fi _wheel="|/-\\" _c=0 _counter=0 printf "Browsing URLs." for i in {1..100} ; do printf "\010%s" ${_wheel:$_c:1} let _c="_c + 1" if [ $_c -gt 3 ] ; then _c=0 fi let _counter="_counter + 1" if [ $_counter -gt 10 ] ; then _counter=0 printf "\010.|" fi done { for j in `cat $1` do echo "$j - `HEAD -d $j`" done } > "/tmp/output.text" 2>&1 printf "\n" It is showing only Browsing URLs.........\ My input text file contains 600+ urls. Does the progress bar will show until the script process all of my URLs? can you please fix my problem. |