logfilter 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/perl
  2. # Filter the rsync daemon log messages by module name. The log file can be
  3. # in either syslog format or rsync's own log-file format. Note that the
  4. # MODULE_NAME parameter is used in a regular-expression match in order to
  5. # allow regex wildcards to be used. You can also limit the output by
  6. # directory hierarchy in a module. Examples:
  7. #
  8. # logfilter foo /var/log/rsyncd.log # output lines for module foo
  9. # logfilter foo/dir /var/log/syslog # limit lines to those in dir of foo
  10. use strict;
  11. my $match = shift;
  12. die "Usage: logfilter MODULE_NAME [LOGFILE ...]\n" unless defined $match;
  13. my $syslog_prefix = '\w\w\w +\d+ \d\d:\d\d:\d\d \S+ rsyncd';
  14. my $rsyncd_prefix = '\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d ';
  15. my %pids;
  16. while (<>) {
  17. my($pid,$msg) = /^(?:$syslog_prefix|$rsyncd_prefix)\[(\d+)\]:? (.*)/o;
  18. next unless defined $pid;
  19. my($mod_spec) = $msg =~ /^rsync (?:on|to) (\S+) from /;
  20. if (defined $mod_spec) {
  21. if ($mod_spec =~ /^$match(\/\S*)?$/o) {
  22. $pids{$pid} = 1;
  23. } else {
  24. delete $pids{$pid};
  25. }
  26. }
  27. next unless $pids{$pid};
  28. print $_;
  29. }