#!/usr/bin/perl -w # $Id: gauge.pl,v 1.1.1.1 2005/04/05 08:38:24 felix Exp $ use POSIX qw(strftime); # my $cmd="dialog"; # my $cmd="gdialog"; my $cmd="whiptail"; $cmd=$ENV{'DIALOG'} if $ENV{'DIALOG'}; my $file=$ARGV[0]; my $sze=( stat $file)[7]; my ($x,$y)=`echo -e cols\\\\nlines|tput -S`=~/^(\d+)[^\d]+(\d+)[^\d]+$/x; $cmd=sprintf "%s --backtitle \"(C) 2005 F. Hauri%". ($x-19)."s\" --gauge \"Lecture de %s\" %d %d 0", $cmd, strftime("%d-%m-%y %T",localtime()),$file,$y-5,$x-4; open IN,"<$file" or die "cannot open $file"; open GAUGE,"| $cmd >/dev/tty" or die "Cannot run gauge"; my $buf; my $now=my $tim=time(); my $tot=0; my $read=-1; while ( $read != 0 ) { $read=sysread IN,$buf,102400; $tot=$tot+$read; syswrite GAUGE,sprintf "%.f\n",$tot/$sze*100; if (time > $now) { $now=time(); my $spd=$tot/($now-$tim); syswrite GAUGE,sprintf "XXX\n\nLecture de %s : %.2fK/s -> fin: %s\nXXX\n", $file , $spd/1024, strftime("%d-%m-%y %T",localtime($now+($sze-$tot)/$spd)); } syswrite STDOUT,$buf; }; close GAUGE; close IN