| 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 | |
| 11 | use strict; |
| 12 | |
| 13 | my $match = shift; |
| 14 | die "Usage: logfilter MODULE_NAME [LOGFILE ...]\n" unless defined $match; |
| 15 | |
| 16 | my $syslog_prefix = '\w\w\w +\d+ \d\d:\d\d:\d\d \S+ rsyncd'; |
| 17 | my $rsyncd_prefix = '\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d '; |
| 18 | |
| 19 | my %pids; |
| 20 | |
| 21 | while (<>) { |
| 22 | my($pid,$msg) = /^(?:$syslog_prefix|$rsyncd_prefix)\[(\d+)\]:? (.*)/o; |
| 23 | next unless defined $pid; |
| 24 | my($mod_spec) = $msg =~ /^rsync (?:on|to) (\S+) from /; |
| 25 | if (defined $mod_spec) { |
| 26 | if ($mod_spec =~ /^$match(\/\S*)?$/o) { |
| 27 | $pids{$pid} = 1; |
| 28 | } else { |
| 29 | delete $pids{$pid}; |
| 30 | } |
| 31 | } |
| 32 | next unless $pids{$pid}; |
| 33 | print $_; |
| 34 | } |