Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Add Progress Bar to Bash script?

  1. #1
    Join Date
    Mar 2007
    Location
    TN, US
    Beans
    607
    Distro
    Ubuntu

    Add Progress Bar to Bash script?

    So How do you? I am trying to touch up a script that i wrote a while back, and a progress bar would go a long way toward helping make the script easier to use. Thanks for the help!!
    Registered Linux user 446122 , Registered Machine 352936.

  2. #2
    Join Date
    Jan 2007
    Beans
    61

    Re: Add Progress Bar to Bash script?

    if by progress bar you mean something like:

    (================================)

    there are a few ways you could do it, I'm not sure what to recommend without knowing more about your program.

    The simplest example I can think of is, let's say your program can be divided into 20 different steps, you could just print out an equal sign for each step.

    A more complicated one would be if you're trying to download a file, since your program would probably be suspended during the download you'd need to fork() the execution and have it output = signs representative of the percentage of the file is downloaded.
    Specs: Intel Core 2 Duo e6600; ASUS P5N-E SLI; GeForce 7600GT; 2 GB DDR2 800MHz RAM
    Ubuntu Feisty 7.06 and Window XP

  3. #3
    Join Date
    Mar 2007
    Location
    TN, US
    Beans
    607
    Distro
    Ubuntu

    Re: Add Progress Bar to Bash script?

    Quote Originally Posted by Sp4cedOut View Post
    if by progress bar you mean something like:

    (================================)

    there are a few ways you could do it, I'm not sure what to recommend without knowing more about your program.

    The simplest example I can think of is, let's say your program can be divided into 20 different steps, you could just print out an equal sign for each step.

    A more complicated one would be if you're trying to download a file, since your program would probably be suspended during the download you'd need to fork() the execution and have it output = signs representative of the percentage of the file is downloaded.
    This would actually be to monitor the progress of the dd command. I will attach the script I am updating if that helps. Thanks for the help!!
    Attached Files Attached Files
    Registered Linux user 446122 , Registered Machine 352936.

  4. #4
    Join Date
    Oct 2004
    Location
    Pennsylvania
    Beans
    1,698

    Re: Add Progress Bar to Bash script?

    Quote Originally Posted by brennydoogles View Post
    So How do you? I am trying to touch up a script that i wrote a while back, and a progress bar would go a long way toward helping make the script easier to use. Thanks for the help!!
    This utility might help http://clpbar.sourceforge.net/.

  5. #5
    Join Date
    Mar 2007
    Location
    TN, US
    Beans
    607
    Distro
    Ubuntu

    Re: Add Progress Bar to Bash script?

    Quote Originally Posted by cwaldbieser View Post
    This utility might help http://clpbar.sourceforge.net/.
    It looks like what I would need, but I am unsure as to how I would need to integrate it into my script. Any suggestions??
    Registered Linux user 446122 , Registered Machine 352936.

  6. #6
    Join Date
    May 2005
    Location
    US
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Add Progress Bar to Bash script?

    Have you thought about using Zenity?
    http://linux.byexamples.com/archives...og-examples-2/

  7. #7
    Join Date
    Mar 2007
    Location
    somewhere cold
    Beans
    70
    Distro
    Kubuntu 8.10 Intrepid Ibex

    Re: Add Progress Bar to Bash script?

    In *theory* all you need to create a progress bar is:

    start
    current
    end

    I.E. - with dd you are most likely going to be using file size to determine progress. Start will be 0, current will be the current size of the file, and end will be the final size of the file. You could use a tool like du to find the size of the file as it is being created, and hopefully you can do the same on the DVD to find the total size of the file. Then, inside your script you need to have a loop that will look at the current size of the file as opposed to the final size, calculate a 'percentage complete' and then use that to determine how much of the progress bar to show.

    Hope that gives you a starting point. I can whip up some code if you want an example.
    for beer in $(ls /home/fridge); do
    drink $beer
    done

  8. #8
    Join Date
    Oct 2004
    Location
    Pennsylvania
    Beans
    1,698

    Re: Add Progress Bar to Bash script?

    Quote Originally Posted by brennydoogles View Post
    It looks like what I would need, but I am unsure as to how I would need to integrate it into my script. Any suggestions??
    I think you would just replace your "dd" command with something like:
    Code:
    dd if="$INFILE" | ./bar -s $EXPECTED_SIZE | dd of="$OUTFILE" ;
    There seem to be a slew of options to the utility (try ./bar -h 2>&1 | less).

  9. #9
    Join Date
    Mar 2007
    Location
    TN, US
    Beans
    607
    Distro
    Ubuntu

    Re: Add Progress Bar to Bash script?

    Quote Originally Posted by cwaldbieser View Post
    I think you would just replace your "dd" command with something like:
    Code:
    dd if="$INFILE" | ./bar -s $EXPECTED_SIZE | dd of="$OUTFILE" ;
    There seem to be a slew of options to the utility (try ./bar -h 2>&1 | less).
    ok, so the code above spit out an error message, and i think I'm lost. Here is the script:
    Code:
    #!/bin/bash
    ##This is a script to simply and easily copy DVDs to your hard drive from the command line
    ##For help send an email to wishingforayer@gmail.com	
    ############################################################################################################################################################
    #####################################################		Variable Declaration		############################################################
    ############################################################################################################################################################
    safemk () {
    if [ ! -d $1 ]; 
      then mkdir $1; 
      chmod +rw $1; 
    fi
    }
    
    MYHOME=/home/$USER
    VIDEO=/home/$USER/video/dvds
    ############################################################################################################################################################
    #####################################################		Scripted Action			############################################################
    ############################################################################################################################################################
            echo -e "Hello" $USER", How are you??"	
    	echo -e "Where would you like the ISO created?"
               OPTIONS="Home User-Specified Video/dvd QUIT"
               select opt in $OPTIONS; do
                   if [ "$opt" = "Home" ]; then                
                    DIRECTORY=$MYHOME
                   elif [ "$opt" = "User-Specified" ]; then
                    echo -e "Please enter the directory into which you would like to create your ISO: " 
    		read  DIRECTORY
    	       elif [ "$opt" = "Video/dvd" ]; then
                     safemk video/dvds
    		 DIRECTORY=$VIDEO
    	       elif [ "$opt" = "QUIT" ]; then
    		 exit 0
                   else
                    clear
                    echo "That wasn't one of the options."
                   fi
                   break
               done
    	echo -e "Please enter the desired filename for your ISO: " 
    	read "FILENAME"
    	dd if=/dev/cdrom | bar -s $EXPECTED_SIZE | dd of=$DIRECTORY/"$FILENAME".iso
    	eject /dev/cdrom
    	exit 0
    and here is the error:
    Code:
    brendon@brendon-linux:~/devbin$ ./cpdvdpb.sh 
    Hello brendon, How are you??
    Where would you like the ISO created?
    1) Home
    2) User-Specified
    3) Video/dvd
    4) QUIT
    #? 1
    Please enter the desired filename for your ISO: 
    cod
    *** ERROR: [2]: No such file or directory
               Missing size after -s
    0+0 records in
    0+0 records out
    0 bytes (0 B) copied, 2.688e-05 seconds, 0.0 kB/s
    brendon@brendon-linux:~/devbin$
    Any Ideas??
    Registered Linux user 446122 , Registered Machine 352936.

  10. #10
    Join Date
    Mar 2006
    Location
    New Zealand
    Beans
    607
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Add Progress Bar to Bash script?

    Code:
    dd if=/dev/cdrom | bar -s $EXPECTED_SIZE | dd of=$DIRECTORY/"$FILENAME".iso
    Your $EXPECTED_SIZE variable is empty no?

    is that ment to be of? or if?

    dd if=/
    dd of=

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •