Date: Fri, 22 Feb 2002 00:18:58 -0800 From: "Crist J. Clark" <crist.clark@attbi.com> To: "Eric I.Arnoth" <earnoth@comcast.net> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: syslog.conf problems Message-ID: <20020222001858.I48401@blossom.cjclark.org> In-Reply-To: <20020222033846.MDLM14626.femail23.sdc1.sfba.home.com@there>; from earnoth@comcast.net on Thu, Feb 21, 2002 at 10:36:02PM -0500 References: <20020221030958.QQRM18863.femail11.sdc1.sfba.home.com@there> <20020221041623.Q48401@blossom.cjclark.org> <20020222033846.MDLM14626.femail23.sdc1.sfba.home.com@there>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Feb 21, 2002 at 10:36:02PM -0500, Eric I.Arnoth wrote: > On Thursday 21 February 2002 07:16, you wrote: > > > > You'll kick yourself. Is /hello_log.sh set executable? > > Ugghh....no, it wasn't. <sigh> > > Now that I chmod'd it properly, the bourne scipt runs just fine. I then > tried to make it echo the line to my python script, thusly: > -------------------------------------------------------- > #!/bin/sh > read line > echo "$line" | /hello_log.py > -------------------------------------------------------- > It works just fine. Thus explaining to me the man page's comments about > shell script wrapper to set up the run-once-and-die mechanism. > > So now that I have the proof of concept, I can do whatever I want in Python, > such as parse the output and send it to Postgresql. > > Thanks much for the simple assist, though I am quite embarassed that it was > such a simple detail. I still don't understand why the Python script on it > won't run properly. (It is 755 perm ;-) > > hello_log.py > -------------------------------------------------------- > #!/usr/local/bin/python > import sys > > test_file = open("/test.out", 'a') > test_file.write(sys.__stdin__.read()) > test_file.flush() > test_file.close() > sys.exit() > -------------------------------------------------------- Sorry, I'm not python fluent. It's obvious that you've read the manpage. What syslogd(8) does is execute the program it is given (really it runs a sh(1) which runs the program) the first time it gets a line for it. It _does not_ close the pipe to the program, but keeps it open ready to send the next line. When you run the shell wrapper, it reads the one line, feeds it to the python script, and _the shell_ exits. Like I said, I'm not python fluent, but this perl(1) example works fine, #!/usr/bin/perl -w open(LOG, '>>/var/log/syslog_test.log') || die('cannot append syslog_test.log'); chomp($line = <STDIN>); printf LOG "%s len = %d\n", $line, length($line); To log one line at a time. Read one line and quit. However, if your program is waiting for more input... it will hang there waiting for more and nothing will be output to the file until it decides to flush the buffer. It looks like that's what your python program is trying to do, but I don't know enough about implementation details of python to know why it doesn't work. -- Crist J. Clark | cjclark@alum.mit.edu | cjclark@jhu.edu http://people.freebsd.org/~cjc/ | cjc@freebsd.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020222001858.I48401>