View Full Version : Wget and zenity --progress
Mathieu11
November 25th, 2006, 05:27 AM
Hello,
I'm making a little nautilus script to get a copy of a whole website on my harddisk.
I use the wget function.
I'd like to get a progressbar with zenity to show the advancement of the wget function.
Anyone know how I could do it ?
This doesn't work :
wget -r -l$recursion -k -E $adresse | zenity --progress --pulsate --auto-close
PS : I do not wish to use the wget --progress function that I know, as it only shows progress in the terminal.
Twigman
December 6th, 2006, 05:24 AM
wget http://filename 2>&1 | sed -u 's/.*\ \([0-9]\+%\)\ \+\([0-9.]\+\ [KMB\/s]\+\)$/\1\n# Downloading \2/' | zenity --progress --title="Downloading File..."
That will print the download rate and also advance the progress bar.
This will only work if wget is printing the download percentages.. and that will only work if wget knows how far along it is... I've used that successfully when downloading single files..
Hope it helps..
Twigman
Twigman
December 6th, 2006, 05:26 AM
Thought I should just explain what that code actually does ;)
wget .... 2>&1 merges the stderr output into stdout
sed -u '.....' mangles the output from wget so that it appears like this:
1%
# Downloading (bitrate)
2%
# Downloading (bitrate)
the -u parameter means 'don't buffer much'
# means update the text in the dialog for zenity..
and the zenity part is fairly obvious...
goodrench
March 18th, 2008, 10:50 AM
Thought I should just explain what that code actually does ;)
wget .... 2>&1 merges the stderr output into stdout
sed -u '.....' mangles the output from wget so that it appears like this:
1%
# Downloading (bitrate)
2%
# Downloading (bitrate)
the -u parameter means 'don't buffer much'
# means update the text in the dialog for zenity..
and the zenity part is fairly obvious...
does this only work with wget?
I have some scripts that I would like to give this feature to but I can't figure out how to do it.
I want to use it with mencoder functions.
Is this possible?
jobsonandrew
March 27th, 2008, 06:08 AM
Hi, thanks for the code example for the progress bar.. but i have a problem with it:
if you cancel the dialog, wget keeps running... and the only way to stop it is to end it with the system monitor or kill it in the terminal
any idea how to fix this?
goodrench
March 27th, 2008, 08:11 AM
Hi, thanks for the code example for the progress bar.. but i have a problem with it:
if you cancel the dialog, wget keeps running... and the only way to stop it is to end it with the system monitor or kill it in the terminal
any idea how to fix this?
add
--auto-kill
to the zenity options
jobsonandrew
March 27th, 2008, 08:37 AM
yeah I tried using --auto-kill but it doesnt work.. I think it actually kills sed.. as that is whats feeding the progress box..?
because of this it doesnt kill wget
bodhi.zazen
June 14th, 2008, 03:08 AM
This is an old thread, but I found it as I was having a similar problem.
There is a bug report here :
https://bugs.launchpad.net/ubuntu/+source/zenity/+bug/220656
The "problem" is --auto-kill , I think, refers to killing the zenity progress dialog at 100 %.
In this case, wget keeps running ....
I do not have a solution, just a work around ...
Note: Thanks Twigman for the awesome sed expression ...
To contine with the wget / zenity expression used by Twigman :
# Start wget | zenity
# Note the & at the end of the pipe, this allows the script to continue with wget running in the background
wget http://filename (http://filename/) 2>&1 | sed -u 's/.*\ \([0-9]\+%\)\ \+\([0-9.]\+\ [KMB\/s]\+\)$/\1\n# Downloading \2/' | zenity --progress --title="Downloading File..." &
#Start a loop testing if zenity is running, and if not kill wget
RUNNING=0
while [ $RUNNING -eq 0 ]
do
if [ -z "$(pidof zenity)" ]
then
pkill wget
RUNNING=1
fi
doneThis will stop wget if zenity is killed (ie cancel button is hit).
This will leave a partially downloaded file, so you may want to clean up after killing wget.
It is an ugly hack, and there may be a better way, but that is the best I could do.
Martje_001
June 14th, 2008, 03:15 AM
bodhi.zazen: Why didn't you add a sleep in the loop..? this consumes way too much CPU.
unrater
June 14th, 2008, 08:56 AM
Twigman, thank you thank you thank you :)
bodhi.zazen
June 18th, 2008, 01:34 AM
bodhi.zazen: Why didn't you add a sleep in the loop..? this consumes way too much CPU.
Um, err, the dog ate it ?
gigahz
July 14th, 2008, 03:50 AM
wow I like sed more and more but even more the examples helping me understand the manual.
This was cool
gigahz
June 13th, 2009, 04:17 AM
Hi I used this hack for a while but now in jaunty things seem to be different? Anyway, the second line works for me in jaunty:
wget http://(url) 2>&1 | sed -u 's/.*\ \([0-9]\+%\)\ \+\([0-9.]\+\ [KMB\/s]\+\)$/\1\n# Downloading \2/' | zenity --progress --title="Downloading" --auto-close
wget http://(url) 2>&1 | sed -u 's/.* \([0-9]%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --title="Downloading" --auto-close
my wget version in jaunty is GNU Wget 1.11.4. To mee it seems spaces are not backslashed anymore (?) :)
gigahz
June 14th, 2009, 11:52 AM
second line:
wget http://(url) 2>&1 | sed -u 's/.* \([0-9]%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --title="Downloading" --auto-close
Sorry, I forgot to include more than one percentage digit, see the \+ just before % below:
second line:
wget http://(url) 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, ETA \3/' | zenity --progress --title="Downloading" --auto-close
Anyway, this version includes Estimated Time of Arrival for the impatient :)
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.