javier arturo rodríguez

countdown

20051230 9:53 by javier

This small script is an alternative to sleep(1) that gives a visual clue to the user about the remaining seconds in the delay

#!/usr/bin/perl
$|++;

my $secs = shift;
die(“Usage: $0 <secs>\n) unless (defined $secs) && ($secs>=0);
while($secs>0) {
        printf(\r% 4d”, $secs);
        sleep 1;
        –$secs;
}
print “Done          \n;

(Download)
There are numerous instances where you might want your shell scripts to sleep(1) giving the user a clue about what’s going on, but just to relate to a previous example, let’s see how this can be used to throttle file leeching:

$ for i in `count 1 10 %02d`; do wget http://…./file-$i.pdf; countdown 30; done

Leave a Reply

32 queries. 0.379s  $Revision: 1.6 $
Use Any Browser! Valid XHTML 1.0   Powered by WordPress Powered by Apache Web Server Hacker Emblem