watchdump.pl 930B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use Getopt::Long;
  5. my $opts;
  6. $opts->{no_header} = 0;
  7. $opts->{delay} = 2;
  8. $opts->{frames} = "-/|\\";
  9. GetOptions (
  10. "no-header" => \$opts->{no_header},
  11. "usage" => \$opts->{usage},
  12. "help" => \$opts->{usage},
  13. "delay=i" => \$opts->{delay},
  14. "frames=s" => \$opts->{frames},
  15. ) or &usage;
  16. &usage if $opts->{usage};
  17. sub usage {
  18. print "usage: watchdump.pl --no-header --delay=SEC --frames=CHARS FILE\n";
  19. exit 0;
  20. }
  21. my @frames = split "", $opts->{frames};
  22. my $frame_num = 0;
  23. sub get_frame {
  24. my $frame = $frames[$frame_num];
  25. $frame_num++;
  26. $frame_num = 0 if $frame_num > $#frames;
  27. return $frame;
  28. }
  29. my $file = shift @ARGV or &usage;
  30. while (1) {
  31. system("clear");
  32. printf "[%s] watching: %s\n%s\n", &get_frame(), $file, "=" x 80
  33. unless $opts->{no_header};
  34. print `cat $file`;
  35. sleep $opts->{delay};
  36. }