From owner-freebsd-questions Fri Feb 22 0:19: 3 2002 Delivered-To: freebsd-questions@freebsd.org Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88]) by hub.freebsd.org (Postfix) with ESMTP id 38A1837B402 for ; Fri, 22 Feb 2002 00:18:59 -0800 (PST) Received: from blossom.cjclark.org ([12.234.91.48]) by rwcrmhc52.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020222081858.QXUR1147.rwcrmhc52.attbi.com@blossom.cjclark.org>; Fri, 22 Feb 2002 08:18:58 +0000 Received: (from cjc@localhost) by blossom.cjclark.org (8.11.6/8.11.6) id g1M8IwM83656; Fri, 22 Feb 2002 00:18:58 -0800 (PST) (envelope-from cjc) Date: Fri, 22 Feb 2002 00:18:58 -0800 From: "Crist J. Clark" To: "Eric I.Arnoth" Cc: freebsd-questions@FreeBSD.ORG Subject: Re: syslog.conf problems Message-ID: <20020222001858.I48401@blossom.cjclark.org> Reply-To: cjclark@alum.mit.edu References: <20020221030958.QQRM18863.femail11.sdc1.sfba.home.com@there> <20020221041623.Q48401@blossom.cjclark.org> <20020222033846.MDLM14626.femail23.sdc1.sfba.home.com@there> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i 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 X-URL: http://people.freebsd.org/~cjc/ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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. > > 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 = ); 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