-
Notifications
You must be signed in to change notification settings - Fork 5
/
syslog.pl
executable file
·47 lines (41 loc) · 953 Bytes
/
syslog.pl
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
use IO::Socket;
use Time::Local;
use POSIX;
my $buf;
my $Filename, $RotateTime = 0;
my $DEBUG = 0;
$LOGSTAGING="/var/DAD/Logs/LogStaging";
$LOGPROCESSING="/var/DAD/Logs/LogsToProcess";
$sock = IO::Socket::INET->new(LocalPort => '514', Proto => 'udp')||die("Socket: $@");
do{
$sock->recv($buf, 1540);
my ($port, $ipaddr) = sockaddr_in($sock->peername);
@dq = unpack("C4", $ipaddr);
$address = join(".", @dq);
$buf =~ s/^<[0-9]+>//;
logit($address, $buf);
}while(1);
sub logit{
my $host = shift;
my $message = shift;
&RotateLog;
chomp($message);
print LOG "$host $message\n";
if($DEBUG) { print "$host $message\n" }
}
sub RotateLog
{
if(mktime(localtime()) > $RotateTime)
{
if($RotateTime > 0)
{
close(LOG);
rename "$LOGSTAGING/$Filename", "$LOGPROCESSING/$Filename";
}
$RotateTime = mktime(localtime());
$Filename = "syslog.$RotateTime";
open(LOG, ">$LOGSTAGING/$Filename");
$RotateTime += 60;
}
}