From owner-freebsd-questions@FreeBSD.ORG Thu Jun 12 12:15:33 2003 Return-Path: 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 C426137B401 for ; Thu, 12 Jun 2003 12:15:33 -0700 (PDT) Received: from regina.plastikos.com (216-107-106-250.wan.networktel.net [216.107.106.250]) by mx1.FreeBSD.org (Postfix) with ESMTP id E2A7A43FAF for ; Thu, 12 Jun 2003 12:15:32 -0700 (PDT) (envelope-from fullermd@over-yonder.net) Received: from mortis.over-yonder.net (adsl-156-171-156.jan.bellsouth.net [66.156.171.156]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (No client certificate requested) by regina.plastikos.com (Postfix) with ESMTP id 33D6A6EEB9; Thu, 12 Jun 2003 15:15:31 -0400 (EDT) Received: by mortis.over-yonder.net (Postfix, from userid 100) id 6F5E820F2F; Thu, 12 Jun 2003 14:15:29 -0500 (CDT) Date: Thu, 12 Jun 2003 14:15:29 -0500 From: "Matthew D. Fuller" To: "Dave [Hawk-Systems]" Message-ID: <20030612191529.GA33203@over-yonder.net> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i-fullermd.1 X-Editor: vi X-OS: FreeBSD cc: freebsd-questions@freebsd.org Subject: Re: shell scripting - automating rotation of files in different directories X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jun 2003 19:15:34 -0000 On Thu, Jun 12, 2003 at 02:58:32PM -0400 I heard the voice of Dave [Hawk-Systems], and lo! it spake thus: > For example, > > for($i=30; $i>0;$1--){ # 30 days is maximum retained > for LOG in `ls /users/*/logs/ | grep .$i'`; do > # move any of the previous logs into the current existing > # so that we don't add to number of logs per user > $prevLOG = strreplace(($i-1)($i) on $LOG) > mv $prevLOG $LOG > done > ) > > > Am thinking that the shell script will need to drop to awk to perform the > disection of the log number extensions... any thoughts on this/easier methods > before I sit down and devote some time to it? You want jot(1) and expr(1). Something along the lines of: for i in `jot 29 29 1`; do if [ -r /some/dir/log.${i} ] ; then mv -f /some/dir/log.${i} /some/dir/log.`expr "${i}" + 1` fi done (more simplistic than yours, since it doesn't recurse across directories, but the idea gets across) -- Matthew Fuller (MF4839) | fullermd@over-yonder.net Systems/Network Administrator | http://www.over-yonder.net/~fullermd/ "The only reason I'm burning my candle at both ends, is because I haven't figured out how to light the middle yet"