get a copy of the script
#!/usr/bin/perl
use Getopt::Long;
GetOptions("-count=s" => $count,
"-cmd=s" => $cmd);
usage($count, $ARGV[0]);
eval("count_$count("$ARGV[0]", $cmd)");
# ===========================================================================
sub count_down
{
my ($cmd, $fd, $seconds, $time, $x);
($time, $cmd) = @_;
$fd = select(STDOUT); $| = 1; select($fd);
if ($time =~ /:/)
{
$seconds = hms_seconds($time);
}
elsif ($time =~ /^s*d+s*$/)
{
$seconds = $time;
}
for ($x = $seconds ; 0 <= $x ; $x--)
{
printf("%10sr", seconds_hms($x));
sleep( 1 );
}
print("n");
if ($cmd ne "")
{
system("$cmd");
}
}
# ===========================================================================
sub count_up
{
my ($fd, $m, $x);
$fd = select(STDOUT); $| = 1; select($fd);
$m = 0;
printf("%02d: ", $m++);
for ($x = 1 ; ; $x++)
{
if (0 == ($x % 60))
{
printf("n%02d: ", $m++);
}
elsif (0 == ($x % 10))
{
print("0");
}
elsif (0 == ($x % 5))
{
print("+");
}
else
{
print(".");
}
sleep(1);
}
}
# ===========================================================================
sub hms_seconds
{
my ($hms);
($hms) = @_;
$x = $h = $m = $s = 0;
($x, $x, $h, $m, $s) = ($hms =~ /^s*(((d+):)?(d+):)?(d+)s*$/);
return $s + 60 * ($m + 60*$h);
}
# ===========================================================================
sub seconds_hms
{
my ($h, $m, $rval, $s);
($s) = @_;
$m = int($s / 60);
$s = $s % 60;
$h = int($m / 60);
$m = $m % 60;
if (0 < $h)
{
$rval = sprintf("%02d:%02d:%02d", $h, $m, $s);
}
elsif (0 < $m)
{
$rval = sprintf("%02d:%02d", $m, $s);
}
else
{
$rval = sprintf("%02d", $s);
}
return $rval;
}
# ===========================================================================
sub usage
{
my ($count, $limit);
($count, $limit) = @_;
return if ($count eq "up");
return if (($count eq "down") && ($limit ne ""));
print << " EOF";
Usage: chron -count (down ((hh:)mm:)ss [command] | up)
EOF
}
Comments (0)
You don't have permission to comment on this page.