Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
Last active November 14, 2019 02:38
Show Gist options
  • Save heiwa4126/b5520e78a6ae894c1b1ed129ea6fad59 to your computer and use it in GitHub Desktop.
Save heiwa4126/b5520e78a6ae894c1b1ed129ea6fad59 to your computer and use it in GitHub Desktop.
0.5秒ごとにUDPで現在時刻を送りつけるPerlのコード。syslogサーバのテスト用。
#!/usr/bin/env perl
# -*- coding: utf-8 -*-
# for RHEL `sudo yum install perl-Sys-Syslog`
use strict;
use warnings;
use Sys::Syslog qw(:standard setlogsock);
use Time::HiRes qw(gettimeofday usleep);
use POSIX qw(strftime);
use constant TARGET => 'r1'; ### ** UPDATE HERE. hostname or IP ***
setlogsock('udp');
$Sys::Syslog::host = TARGET;
openlog('test', 'ndelay', 'user');
for(;;) {
my ($sec, $usec) = gettimeofday();
syslog('info',sprintf('%s.%03d',strftime('%Y-%m-%d %H:%M:%S',localtime $sec),$usec/1000));
usleep(500000);
}
closelog();
0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment