[NTLUG:Discuss] Script question

Paul Ingendorf pauldy at wantek.net
Fri Jan 4 23:40:18 CST 2002


hmm shell scripts yum gotta throw in how I would do it even though I see a few fine examples have already been posted.
The following would also move the files appropriately.  Just copy and paste this in a file chmod +x it and remember to create the new backup file as /archive/domains.`date +%Y-%m-%d` and it should work properly every time.

#!/bin/bash
rm -f /archive/*.3
let x=3
for file in /archive/domains.[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9].[0-3]
	do
		mv $file /archive/`echo $file | sed -e "s/\.[0-9]^//g"`.$x
		let x=$x-1
	done
mv /archive/domains.`date +%Y-%m-%d` /archive/`date +%Y-%m-%d`.0

-- 
-->> mailto:pauldy at wantek.net
-->> http://www.wantek.net/
Running ....... Cos anything else would be a waste...
`:::'                  .......  ......
 :::  *                  `::.    ::'
 ::: .::  .:.::.  .:: .::  `::. :'
 :::  ::   ::  ::  ::  ::    :::.
 ::: .::. .::  ::.  `::::. .:'  ::.
.:::.....................::'   .::::..


-----Original Message-----
From: discuss-admin at ntlug.org [mailto:discuss-admin at ntlug.org]On Behalf
Of Rick Matthews
Sent: Friday, January 04, 2002 8:18 AM
To: Discuss at Ntlug. Org
Subject: [NTLUG:Discuss] Script question


Would someone please help me over another "hump"? I'm still learning...

I maintain the current version and 3 previous versions of the file
"domains". The files are all in the same directory and the file name
includes a unique date/time stamp and a version number. For example:

domains.2002-01-04_050500.0
domains.2002-01-02_052515.1
domains.2002-01-01_043025.2
domains.2001-12-30_050500.3

'0' is the current version and '3' is the oldest.

When a new file is created I want to "age" the files and create an open
slot for a new "0" file (3 goes away, 2 becomes 3, 1 becomes 2, and 0
becomes 1). I don't know the date/time stamps, so this is what I tried
in my script:

mv -f /archive/domains.*.2 /archive/domains.*.3
mv -f /archive/domains.*.1 /archive/domains.*.2
mv -f /archive/domains.*.0 /archive/domains.*.1

The asterisk apparently acts as a wildcard during the file selection
part of the command, but it is acting as a literal in the renaming
porting of the command (I end up with files named domains.*.3).

How can I rewrite this to accomplish the task?

Thanks in advance!

Rick Matthews


_______________________________________________
http://www.ntlug.org/mailman/listinfo/discuss





More information about the Discuss mailing list