watchdump.pl 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. sub clear {
  30. system "cls" if -d "c:\\windows";
  31. system "clear" if -f "/bin/ls";
  32. }
  33. my $file = shift @ARGV or &usage;
  34. while (1) {
  35. &clear;
  36. system "title $file" if -d "c:\\windows";
  37. printf "[%s] watching: %s\n%s\n", &get_frame(), $file, "=" x 80
  38. unless $opts->{no_header};
  39. if (open my $fh, "<", $file) {
  40. print join "", <$fh>;
  41. close $file;
  42. } else { warn "cannot open $file: $!\n"; next; }
  43. } continue {
  44. sleep $opts->{delay};
  45. }