Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Jun 2003 14:15:29 -0500
From:      "Matthew D. Fuller" <fullermd@over-yonder.net>
To:        "Dave [Hawk-Systems]" <dave@hawk-systems.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: shell scripting - automating rotation of files in different directories
Message-ID:  <20030612191529.GA33203@over-yonder.net>
In-Reply-To: <DBEIKNMKGOBGNDHAAKGNEEELAIAC.dave@hawk-systems.com>
References:  <DBEIKNMKGOBGNDHAAKGNEEELAIAC.dave@hawk-systems.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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,
> <brutally pseudo script>
> 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
> )
> </brutally pseudoscript>
> 
> 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"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030612191529.GA33203>