From: "Russ Cox" <rsc@swtch.com>
To: 9fans@9fans.net
Subject: Re: [9fans] syslog to bsd/linux systems
Date: Mon, 26 May 2008 16:41:50 -0700 [thread overview]
Message-ID: <20080526234026.5F2661E8C54@holo.morphisms.net> (raw)
In-Reply-To: <13426df10805260915r69e8d6e3i4a63b451e6ad7b9f@mail.gmail.com>
> I know this question has been addressed before but I hvae not yet
> found the discussion.
>
> I am moving 9grid.net to a new location in california, but the site is
> requesting that I send all syslog output to a linux host.
>
> Anyone recall simple solution here? It's tempting to just do it via
> shell script, for fun, but if somebody's got a known good setup that
> would save me some time.
I don't understand the problem. Since Plan 9 doesn't
generate any syslog output, you're already sending it
all to their linux host.
I don't remember whether the code below actually works.
Russ
#include <u.h>
#include <libc.h>
#include <bio.h>
enum
{
FSystem = 3, // facility: system daemons
SInfo = 6, // severity: informational
};
void
usage(void)
{
fprint(2, "usage: cat log-source | syslog [-p pri] [-h host] [-t tag] addr\n");
exits("usage");
}
char *mon = "JanFebMarAprMayJunJulAugSepOctNovDec";
void
main(int argc, char **argv)
{
int pri, fd, n;
char *host;
Biobuf b;
char *p, msg[1000], *tag;
Tm *tm;
pri = FSystem*8 + SInfo;
host = sysname();
tag = "zzz";
ARGBEGIN{
case 'p':
pri = atoi(EARGF(usage()));
break;
case 'h':
host = EARGF(usage());
break;
case 't':
tag = EARGF(usage());
break;
default:
usage();
}ARGEND
if(argc != 1)
usage();
fd = dial(netmkaddr(argv[0], "udp", "syslog"), nil, nil, nil);
if(fd < 0)
sysfatal("dial %s: %r", argv[0]);
Binit(&b, 0, OREAD);
while((p = Brdstr(&b, '\n', 1)) != nil){
tm = localtime(time(0));
n = snprint(msg, sizeof msg,
"<%d>%.3s %02d %02d:%02d:%02d %s %s: %s",
pri, mon+tm->mon*3, tm->mday, tm->hour, tm->min, tm->sec,
host, tag, p);
free(p);
write(2, msg, n);
write(fd, msg, n);
}
exits(0);
}
next prev parent reply other threads:[~2008-05-26 23:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-26 16:15 ron minnich
2008-05-26 17:47 ` Williams, Mitch
2008-05-27 8:41 ` Steve Simon
2008-05-26 23:41 ` Russ Cox [this message]
2008-05-27 4:09 ` ron minnich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080526234026.5F2661E8C54@holo.morphisms.net \
--to=rsc@swtch.com \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).