Last active
November 14, 2019 02:38
-
-
Save heiwa4126/b5520e78a6ae894c1b1ed129ea6fad59 to your computer and use it in GitHub Desktop.
0.5秒ごとにUDPで現在時刻を送りつけるPerlのコード。syslogサーバのテスト用。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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