From owner-freebsd-questions@FreeBSD.ORG Tue Jun 21 09:24:07 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 4F2C516A41C for ; Tue, 21 Jun 2005 09:24:07 +0000 (GMT) (envelope-from cknipe@hybyte.com) Received: from ctb-mesg5.saix.net (ctb-mesg5.saix.net [196.25.240.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id A64B943D55 for ; Tue, 21 Jun 2005 09:24:06 +0000 (GMT) (envelope-from cknipe@hybyte.com) Received: from smtp01.za.hybyte.net (wbs-146-184-170.telkomadsl.co.za [165.146.184.170]) by ctb-mesg5.saix.net (Postfix) with ESMTP id C5B343D1C for ; Tue, 21 Jun 2005 11:23:44 +0200 (SAST) Received: from 030-001.za.hybyte.net ([192.168.1.30] helo=pc2xp) by smtp01.za.hybyte.net with esmtp (Exim 4.50) id 1Dkeys-0003J8-r3 for freebsd-questions@freebsd.org; Tue, 21 Jun 2005 11:23:42 +0200 Message-ID: <000601c57642$edfce460$1e01a8c0@pc2xp> From: "Chris Knipe" To: Date: Tue, 21 Jun 2005 11:23:46 +0200 MIME-Version: 1.0 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: OT Shell Script 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: Tue, 21 Jun 2005 09:24:07 -0000 May be a bit off topic, but I don't know any sh scripting lists that I'm = subscribed to... :) If I run the script from shell / console, it runs without a problem.... = Running it via cron, I get: [: 6: unexpected operator The script: #!/bin/sh HOSTNAME=3D`/usr/bin/uname -n` SIZE=3D`/usr/bin/du /var/log/MYAPP/|/usr/bin/cut -c 1-7` ROTATE=3D"1024000" if [ -e /tmp/.rotate ]; then return 1 else touch /tmp/.rotate if [ $SIZE -ge $ROTATE ]; then /bin/mkdir -p /usr/local/backup/var/logs cd /usr/local/backup/var/logs for X in `ls /var/log/MYAPP/`; do rm -f $X.9.tgz mv $X.8.tgz $X.9.tgz mv $X.7.tgz $X.8.tgz mv $X.6.tgz $X.7.tgz mv $X.5.tgz $X.6.tgz mv $X.4.tgz $X.5.tgz mv $X.3.tgz $X.4.tgz mv $X.2.tgz $X.3.tgz mv $X.1.tgz $X.2.tgz /usr/bin/tar -czf $X.1.tgz /var/log/MYAPP/$X > /dev/null /bin/cat /dev/null > /var/log/MYAPP/$X done /bin/echo "/var/log/MYAPP Rotated on $HOSTNAME" | /usr/bin/mail -s = "MYAPP Log Rotation" my@somwhere fi /bin/rm /tmp/.rotate fi No, unfortunately, I MUST script this, I cannot use logrotate / = newsyslog / name your fav log rotation tool, as they all destroy active = file handles on the log file. cating /dev/null to the log is a good way = to clean the log, whilst allowing a MULTITUDE of applicating writing to = the file, to keep their file handles in tact....=20 Anyone that can give me a indication of what is going haywire in the = script? Thank you kindly, Chris.