File: hostlist

package info (click to toggle)
logwatch 5.2.2-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,112 kB
  • ctags: 42
  • sloc: perl: 9,032; sh: 65; makefile: 54
file content (34 lines) | stat: -rwxr-xr-x 654 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/perl -w
use strict;

my $TempDir = $ENV{'LOGWATCH_TEMP_DIR'};

my ($line, $host,$tothost);
my @hostlist;
my $HostFile = ("$TempDir" . "hostfile");
if (-f $HostFile) {
   open (TEMPFILE,$HostFile);
   @hostlist = <TEMPFILE>;
   close (TEMPFILE);
}

while (defined($line = <STDIN>)) {
   if ($line =~ m/^... .. ..:..:.. (\S*)/io) {
      $host = $1;
      if (grep(m/$host/,@hostlist)) {
      } else {
         push @hostlist,$host;
      }
   }
}

open (TEMPFILE,">$HostFile") || die $!;
foreach $tothost (@hostlist) {
   chomp $tothost;
   if (length($tothost) == "0") {
   } else {
      print TEMPFILE "$tothost\n";
   }
}
close TEMPFILE;