Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have dialog installed, where I would like to have a nice progress dialog, like this:

+-------[ title ]--------+
|                        |
| +-[ console output ]-+ |
| | output line11      ^ |
| | output line12      | |
| | output line13      | |
| | output line14      # |
| | output line15      | |
| | output line16      v |
| +--------------------+ |
| #########80%#####::::: |
+------------------------+

So, for example when upgrading 5 packages in a distro, it shows the progress (here, 4 package is upgraded out of 5 ie. 80%), but shows the detailed output of the executed commands. Is this possible?

I suspect it is, but I cannot get a working solution with --tailboxbg and --gauge.

share|improve this question
    
This kind of complex dialogs can be generated using gtkdialog. Sorry, no detailed hints on exactly how, as I didn't managed yet to make it work on my system. –  manatwork May 28 '13 at 10:04

1 Answer 1

Right, you can do it with --gauge:

#!/bin/bash
declare PACKAGES=("/etc/crontab"  "/etc/dmtab"  "/etc/fstab"  "/etc/inittab"  "/etc/mtab")
NUM_PACKAGES=${#PACKAGES[*]} # no. of packages to update (#packages in the array $PACKAGES)
step=$((100/$NUM_PACKAGES))  # progress bar step
cur_file_idx=0
counter=0
DEST=${HOME}
(
# infinite while loop
while :
do
    cat <<EOF
XXX
$counter
$counter% upgraded

$COMMAND
XXX
EOF
    COMMAND="cp ${PACKAGES[$cur_file_idx]} $DEST &>/dev/null" # sets/updates command to exec.
    [[ $NUM_PACKAGES -lt $cur_file_idx ]] && $COMMAND # executes command

    (( cur_file_idx+=1 )) # increase counter
    (( counter+=step ))
    [ $counter -gt 100 ] && break  # break when reach the 100% (or greater
                                   # since Bash only does integer arithmetic)
    sleep 10 # delay it a specified amount of time i.e. 1 sec
done
) |
dialog --title "File upgrade" --gauge "Please wait..." 10 70 0

This code in action:

            progress bar animation

Note. This code actually copies those five files from /etc/ into your $HOME folder.

share|improve this answer
    
Thanks, I was aware of this possibility, however, I'd like to have a solution, where I can view the full output of the commands run. –  pihentagy May 27 '13 at 12:21
    
1) As bash does only integer arithmetic, is possible to not reach a total of 100 due to the truncated steps. 2) That indented here-document will fail to execute. 3) Initializing the counter with the number of packages is out of logic. 4) The parenthesis () around the while is pointless. 5) You have typo too: NUM_PACAKGES. –  manatwork May 27 '13 at 12:25
    
@manatwork Thanks for your clarification. I've tested the code and then updated. –  Alberte Romero May 27 '13 at 14:21
    
Nice answer, but I would like to see all outputs, so in this case all the cp commands (very long list), and able to scroll back –  pihentagy May 28 '13 at 9:57
    
I've tested the code and I see that only prints the commands really it does not copy anything, is it the expected behaviour of gauge widget? –  sebelk May 23 '14 at 3:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.