Hello,
In perl how to show the percentage download when we download something wget ...
For example when we wget some software instead of showing the following ......
[root@server]# wget http://www.mirrors.wiretapped.net/security/network-monitoring/iptraf/iptraf-2.7.0.tar.gz
--06:31:29-- http://www.mirrors.wiretapped.net/security/network-monitoring/iptraf/iptraf-2.7.0.tar.gz
=> `iptraf-2.7.0.tar.gz'
Resolving Wiretapped - Computer Security Software etc.... 203.220.0.26
Connecting to www.mirrors.wiretapped.net|203.220.0.26|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 363,496 (355K) [application/gzip]
100%[==================================================================================================>] 363,496 136.09K/s
06:31:33 (135.83 KB/s) - `iptraf-2.7.0.tar.gz' saved [363496/363496]
============================================
It will show on right hand side ...
1% of 100% complete
and
on left hand side it will show ...
[360/363496] bytes of download complete
Any other suggestions on "perl progress bar dialog" is welcome
Thanks
This is an example. You need to install Term::ReadKey module from CPAN before you can run it.
#!/usr/bin/perl -w
$| = 1;
my $steps = 50;
my $columns = &getTerminalSize()->[1];
for (my $i=1; $i<=$steps; $i++) {
my $percent = ($i/$steps*100);
my $pbwidth = $columns-10;
my $numhashes = ($i/$steps*$pbwidth);
printf("\r% -${pbwidth}s% 10s", '#' x $numhashes, "[ " . $percent . "% ]");
sleep 1;
}
sub getTerminalSize {
use Term::ReadKey;
my ($w, $h) = GetTerminalSize(STDOUT);
if (!defined $w || !defined $h) {
die "Cannot determine terminal size!";
}
return [$h, $w];
}
Output looks like this:
######### [ 14% ]
Fine.. how do I integrate that with wget? And how can the script calculate the percentage value from the results of the wget .. instead of a fixed value defined in the script.
Thanks
Why do you have to integrate with wget? Why not just try LWP in perl instead, or WWW::Curl? I cannot think of any good way to do it unless you have access to a WWW library such as curl or LWP, that you can implement whatever status reporting with it.
Hello,
Thank you for your tips... I am zero where it comes to programming.. but I do have the logic/ideas only. I am starting to learn programming.
Can you give me a script which shows... downloading for example:-
http://www.mirrors.wiretapped.net/security/network-monitoring/iptraf/iptraf-2.7.0.tar.gz
and showing the progress bar
which uses LWP in perl instead, or WWW::Curl
Thanks.