LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need help with dialog(Xdialog) --gauge option (https://www.linuxquestions.org/questions/programming-9/need-help-with-dialog-xdialog-gauge-option-271705/)

zackarya 12-29-2004 07:27 PM

Need help with dialog(Xdialog) --gauge option
 
Hi everyone, I've been searching around but can't really seem to understand how the
--gauge option works for dialog( or Xdialog but I'm currently focusing on just dialog).

What I have is this:

dd if=/dev/urandom of=$fileName bs=1024K count=$fileSize

Where the variables are filled in by the user through dialog. What I want to do is
use gauge to show the file progress while it's creating and more importantly I
would like to understand WHY it works the way it does. I've played around a lot
with different things (using mkfifo, expr) and can get some amount of success but
since I don't understand what's going on I can't get any farther. Thanks.

gnashley 12-29-2004 10:38 PM

Only place I've seen this used was in a Knoppix script (knoppix-autoconfig maybe). I tried to get it to work on Slackware without success.

zackarya 01-03-2005 06:12 PM

Thanks for the reply. I've looked through the knoppix scripts (The little success I've gotten was by using their code.) The areas I'm looking at are:

gauge(){
rm -f "$TMP.done"
status=0
while [ ! -e "$TMP.done" ]; do echo "$status" ; status="`expr \( 100 - $status \) / 4 + $status`"; sleep 2; done | $DIALOG --title "$TITLE1" --gauge "$1" 8 75 0
}

# Stop status bar
killgauge(){
touch "$TMP.done" ; wait ; rm -f "$TMP.done"
}

So here is what they do.

gauge "somemessage" &
dd if=/dev/zero of=$DEVICE bs=1M count=$AMOUNT || { killgauge; sleep 2; bailout; }

the bailout function deletes some temp files, unmounts drives, etc.

Now, when I try to use this in my script it will start creating the file and the dialog pops up,
everything looks good until it get's to about 90% and it slows way down. I know the file is finished creating but gauge never gets to 100%. I don't know enough about the status="`expr`" line to know why this is happening. Can anyone offer any insight. Thanks for your time.

Hko 01-04-2005 06:11 AM

Maybe this bash script helps:
Code:

#!/bin/bash

PIPE="/tmp/pipe_$$"
set -m

mkfifo "$PIPE"
Xdialog --ignore-eof --gauge Aloha 10 30 <"$PIPE" &
sleep 1
for i in `seq 0 20 100` ; do
    echo $i >"$PIPE"
    echo "$i%"
    sleep 1
done

jobs -x kill %%
rm "$PIPE"


zackarya 01-11-2005 02:15 PM

Thanks, I think I get it now.
 
Thanks Hko, I understand it a lot better now. Like I said before I've been trying to get this to work with dd ( or mkfs, etc.) But now it seems that what one really has to do is to simply guess (thus the expr from the knoppix example above) in a way that makes it LOOK like it is keeping track of the current status of the file or whatever. This is a REALLY POOR soultion in my opinion. I have found a few ways that it's possible to know where dd is in the creation process. For instance I found while dd is running I can kill the process and by sending it -USR1 what it does is pause, display how far along it is and continue, sounds like just what I need. The problem though is that this of course stops the file creation for a moment and it seems that the overall overhead is not worth it. Another idea I had would be to have a seperate thread which would just keep doing a du on the file that is being created and compare it to the total filesize it's to create to and use this information to update gauge. Either way it would be more overhead. I havn't seen anyone else who actually checks for the real file progress. It SEEMS that EVERYONE just guesses. So I ask, what is the point of even having a progress bar if the information it displays is not accurate. Maybe I'm missing something here. As a final note I just want to say to everyone here at linuxquestions.org that this forum has become my first stop when looking for information(about Linux). I use to go to google first but I've recently started to realise that google always ends up pointing me back here. So just a big thanks to all of you.

bcnx 08-31-2010 03:42 PM

Hi,

quite an old thread and not sure if anyone watching anymore, but I'm trying to create a dialog gauge as well to show the progress of dd. Sending USR1 to the PID however outputs the statistics to standard error, making it hard to capture them.

Anyone know how?

thx!

B.

gnashley 09-01-2010 02:27 AM

1 Attachment(s)
I'm attaching a small archive with several examples using guage and progressbar which I created. As the last poster mentioned, most people use them with guessed values for the time it takes to perform a task. The only other way is to rpeatedly check the actual progress of the task -if possible. And doing so will slow down the process considerably.
What I usually wound up doing was using some sort of 'spinner' type thing. I've included some examples of that also. They simply display a changing set of characters which look like expanding stars or similar. If using Xdialog, you could even do something similar with a changing icon display.

The attached file is a tar.bz2 archive -just change the '.txt' to '.bz2' to be able to unpack it.

bcnx 09-02-2010 03:25 AM

Gnashley,


thx for your reply and your files. I looked at some, but you don't seem to link the progress of dd to dialog --gauge anywhere, is this right? Is there no way to do this? Because it standard error could be captured, it should be quite easy to calculate how much percent this is of the total file size.

thx again,

Bart


All times are GMT -5. The time now is 03:26 AM.