From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@9fans.net Subject: Re: [9fans] syslog to bsd/linux systems From: "Russ Cox" Date: Mon, 26 May 2008 16:41:50 -0700 In-Reply-To: <13426df10805260915r69e8d6e3i4a63b451e6ad7b9f@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Message-Id: <20080526234026.5F2661E8C54@holo.morphisms.net> Topicbox-Message-UUID: accaf64c-ead3-11e9-9d60-3106f5b1d025 > 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 #include #include 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); }