From owner-freebsd-questions@FreeBSD.ORG Thu Feb 16 22:45:19 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AA1AE16A420 for ; Thu, 16 Feb 2006 22:45:19 +0000 (GMT) (envelope-from tundra@tundraware.com) Received: from eskimo.tundraware.com (eskimo.tundraware.com [64.2.229.164]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1258F43D48 for ; Thu, 16 Feb 2006 22:45:16 +0000 (GMT) (envelope-from tundra@tundraware.com) Received: from [192.168.0.2] (viper.tundraware.com [192.168.0.2]) (authenticated bits=0) by eskimo.tundraware.com (8.13.4/8.13.4) with ESMTP id k1GMjDRS070687 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO) for ; Thu, 16 Feb 2006 16:45:14 -0600 (CST) (envelope-from tundra@tundraware.com) Message-ID: <43F50074.8060205@tundraware.com> Date: Thu, 16 Feb 2006 16:45:08 -0600 From: Tim Daneliuk Organization: TundraWare Inc. User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-TundraWare-MailScanner-Information: Please contact the ISP for more information X-TundraWare-MailScanner: Found to be clean X-MailScanner-From: tundra@tundraware.com Subject: /bin/sh Madness X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: tundra@tundraware.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Feb 2006 22:45:19 -0000 Here is a shell function that behaves quite strangely: #!/bin/sh ##### # Execute A Command, Noting Start/Stop Time, & Logging Output # Args: # $1 Command Name # $2 Log Directory # $3 Command String To Execute ##### runupd() { log=$2/$1.log timestamp $log touch $2/.$1-begin && eval $3 2>&1 >> $log && touch $2/.$1-end & } # End of 'runupd()' So, you might do something like: runupd freespace /var/log/ "df -k" Now, for the weirdness. This function works fine in my script so long as one of two conditions is met: 1) I run it interactively from the command line (bash) OR 2) I run it from 'cron' AND $3 is *not* another script If I try to run it from 'cron' and point $3 to a script, everything gets run as planned, however, the ending timestamp (touch $2/.$1-end) never runs. That is, the initial time stamp (.$1-begin) and the command itself are executed, and output is properly written to the logfile, but the final timestamp never happens. I have been fiddling with this on- and off and cannot seem to explain the behavior. I',m guessing that something about the combination of 'cron'and the 2>&1 >> $log business is causing the last touch to never get invoked, but for the life of me, I cannot figure this one out. Interestingly, this works fine in Linux (SuSE 10.0). In Linux, both 'sh' and 'bash' are the same binary (bash is running as sh). So .. I went back to FreeBSD (4.x in this case, though the problem is also noted in 6.x) and changed the SHELL variable in the crontabs file to use 'bash' - same problem. This is starting to feel like a problem with file handles getting clobbered in the FreeBSD exec logic. Other explanations welcome... -- ---------------------------------------------------------------------------- Tim Daneliuk tundra@tundraware.com PGP Key: http://www.tundraware.com/PGP/