From owner-freebsd-questions@FreeBSD.ORG Mon Sep 12 18:26:19 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 8192816A41F for ; Mon, 12 Sep 2005 18:26:19 +0000 (GMT) (envelope-from pauls@utdallas.edu) Received: from smtp1.utdallas.edu (smtp1.utdallas.edu [129.110.10.12]) by mx1.FreeBSD.org (Postfix) with ESMTP id 45F3F43D45 for ; Mon, 12 Sep 2005 18:26:19 +0000 (GMT) (envelope-from pauls@utdallas.edu) Received: from utd59514.utdallas.edu (utd59514.utdallas.edu [129.110.3.28]) by smtp1.utdallas.edu (Postfix) with ESMTP id 948F3388E52 for ; Mon, 12 Sep 2005 13:26:16 -0500 (CDT) Date: Mon, 12 Sep 2005 13:26:16 -0500 From: Paul Schmehl To: freebsd-questions@freebsd.org Message-ID: <01A14A33D6971135F96609A2@utd59514.utdallas.edu> X-Mailer: Mulberry/3.1.6 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: Shell scripting question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Sep 2005 18:26:19 -0000 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/