[ Please note - this is off the top of my head, so nothing is tested.
There may^H^H^H will be errors in here :-) ]
Personally, I would use an SMF service to wrap my reader, and place a
dependent entry in the manifest something like this:
<dependent
name='mypipe_system-log'
grouping='optional_all'
restart_on='refresh'>
<service_fmri value='svc:/system/system-log' />
</dependent>
Then, syslog will wait until your service is running (i.e. reading from
the pipe) before starting syslog. Moreover, I believe the restart_on
property should restart syslogd if your service dies, is refreshed or is
stopped. A value of 'error' may be sufficient for your service...
Then, to answer your second part, the program must open and continuously
read from the file until EPIPE is received (or some other appropriate
FIFO error). You can do this in something like C or perl explicitly
(like "tail -f" does), but as a quick workaround, try:
tail -f mypipe | script
(and make 'script' read from stdin). Yes tail may insert a delay, but at
least you can quickly workaround the quitting issue. It's not pretty,
but shouldn't require much modification to your script.
If you're using perl, then this works with syslog:
#!/usr/bin/perl -w
use strict;
if (open(PIPE, "< /var/tmp/mypipe")) {
while (<PIPE>) {
print "Read $_";
# Do processing stuff here...
}
}
Hope that helps,
Brian
Harry Putnam wrote:
Brian Ruthven - Solaris Network Sustaining - Sun UK
<[email protected]> writes:
I believe you can create a named pipe (using mkfifo) somewhere in the
filesystem (I'd suggest somewhere persistent, not /tmp or /var/run,
etc...). I've seen it created as /var/log/logpipe or similar. Then
simply name the file in syslog.conf without the '|' symbol.
Haa... ok, that was my error... my linux background.. showing... on
linux syslog you need the pipe there.
However, note that if there is nothing reading from the pipe when
syslogd starts (or when it receives a HUP) then it will ignore it, so
you need to make sure something is reading the pipe before syslog
starts. SMF is probably the best way to do this - you can insert a
dependancy for the svc:/system/system-log service to make sure your pipe
reader starts first.
Also, if there is nothing reading from the pipe when syslogd tries to
write to it, it will close it and ignore it until the next
restart/refresh. However, the smf "restart on" property of the
dependancy can refresh system-log if your reader dies and is restarted.
Thanks, all good info... but one thing... How do you keep the reader
running?
I mean a script using the fifo for input like `script myfifo' quits as
soon as the first line of syslog output comes thru..
Whereas something like `tail -f myfifo' keeps reading.
What I'm after is attaching a perl script to the fifo that is capable
of searching and sorting on any regex or any 2 regex actually, that you
feed the script on startup.
But unlike linux... where the pipe symbol goes into /etc/syslog.conf
on opensolaris my script just quits on the first line of output.
Maybe I can just add some trickiness to the script to make it act like
tail -f... but is that really necessary?
Am I missing something obvious here that would make any script
continue to read from the fifo?
man syslog.conf has no hits on either `fifo' or `pipe' so I'm guessing
there is no help there... I haven't pored through every line but nothing
jumps out as helpful.
_______________________________________________
opensolaris-discuss mailing list
[email protected]
--
Brian Ruthven
Solaris Revenue Product Engineering
Sun Microsystems UK
Sparc House, Guillemont Park, Camberley, GU17 9QG
_______________________________________________
opensolaris-discuss mailing list
[email protected]