From owner-freebsd-questions@FreeBSD.ORG Mon Sep 12 18:37:15 2005 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 48F8716A420 for ; Mon, 12 Sep 2005 18:37:15 +0000 (GMT) (envelope-from Frank.Mueller@emendis.de) Received: from mail.emendis.de (85-10-194-176.clients.your-server.de [85.10.194.176]) by mx1.FreeBSD.org (Postfix) with ESMTP id 27C8C43D45 for ; Mon, 12 Sep 2005 18:37:11 +0000 (GMT) (envelope-from Frank.Mueller@emendis.de) Received: from localhost (mail [127.0.1.4]) by mail.emendis.de (Postfix) with ESMTP id C2C7A60617E; Mon, 12 Sep 2005 20:37:09 +0200 (CEST) Received: from mail.emendis.de ([127.0.1.4]) by localhost (mail.emendis.de [127.0.1.4]) (amavisd-new, port 10024) with ESMTP id 37665-02; Mon, 12 Sep 2005 20:37:09 +0200 (CEST) Received: from [192.168.9.1] (dsl-084-057-127-245.arcor-ip.net [84.57.127.245]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.emendis.de (Postfix) with ESMTP id 96BE5606172; Mon, 12 Sep 2005 20:37:08 +0200 (CEST) Message-ID: <4325CAE2.3020906@emendis.de> Date: Mon, 12 Sep 2005 20:37:22 +0200 From: Frank Mueller - emendis GmbH Organization: emendis GmbH User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050829) X-Accept-Language: de-DE, de, en-us, en MIME-Version: 1.0 To: Paul Schmehl References: <01A14A33D6971135F96609A2@utd59514.utdallas.edu> In-Reply-To: <01A14A33D6971135F96609A2@utd59514.utdallas.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: SPAM/Virenfilter at emendis.de Cc: freebsd-questions@freebsd.org Subject: Re: Shell scripting question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Frank.Mueller@emendis.de List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Sep 2005 18:37:15 -0000 To get the date in the right format you could simply use date +%H Greetz, Ice Paul Schmehl schrieb: > I've written a script to check apache to make sure it's running *and* > logging. One of the variables I create is named DATEHOUR, and it's > created by parsing the output of date in such a way that all I get is > the hour (using awk and cut.) I'm comparing DATEHOUR to LOGHOUR, which > represents the the most recent hour that the log was written to > > I've run in to a small problem I'm not sure how to solve. When the hour > is less than 10, the script generates an arithmetic expression error. > > Here's part of the script so you can visualize what I'm trying to do: > > PROG=/usr/local/sbin/apachectl > LOG=/var/log/httpd-access.log > PID=`/bin/ps -auxw | grep http | grep root | grep -v grep | awk '{print > $2}'` > DATE=`date | awk '{print $4}' | cut -d':' -f1,2` > LOGDATE=`ls -lsa ${LOG} | awk '{print $9}'` > DATEHOUR=`echo ${DATE} | cut -d':' -f1` > LOGHOUR=`echo ${LOGDATE} | cut -d':' -f1` > DATEMIN=`echo ${DATE} | cut -d':' -f2` > LOGMIN=`echo ${LOGDATE} | cut -d':' -f2` > LOGGING=1 > > if [ $((DATEMIN)) -gt $((LOGMIN+15)) ]; then > LOGGING=0 > elif [ $((DATEHOUR)) -ne $((LOGHOUR)) ] && [ $((DATEMIN+60)) -gt > $((LOGMIN+15)) ]; then > LOGGING=0 > fi > > When DATEHOUR is less than 10 (01-09), the script generate an arithmetic > expression, variable substition error. I'm pretty certain it's because > of the leading zero, so I'm trying to figure out how to strip that out. > I thought that parameter expansion would do it, but I get some odd (to > me) results. > > Assume DATE is 09. > > echo ${DATE:0,0} > 09 > echo ${DATE:0,1} > 9 > echo ${DATE:1,1} > 9 > > I would have thought that 0,0 would return only the first character and > 1,1 would return only the second, but that is obviously not the case. > > How can I strip the leading character from the string so that I can test > to see if it's zero? > > Paul Schmehl (pauls@utdallas.edu) > Adjunct Information Security Officer > University of Texas at Dallas > AVIEN Founding Member > http://www.utdallas.edu/ir/security/ > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "freebsd-questions-unsubscribe@freebsd.org" -- Frank Mueller eMail: Frank.Mueller@emendis.de Mobil: +49.177.6858655 Fax: +49.951.3039342 emendis GmbH Hofmannstr. 89, 91052 Erlangen, Germany Fon: +49.9131.817361 Fax: +49.9131.817386 Geschaeftsfuehrer: Gunter Kroeber, Volker Wiesinger Sitz Erlangen, Amtsgericht Fuerth HRB 10116