[NTLUG:Discuss] Script question
Chris Cox
cjcox at acm.org
Fri Jan 4 10:42:16 CST 2002
Fred James wrote:
> I believe you could use "cut" to get what you need to build the new
> file name.
>
> Rick Matthews wrote:
>
>> 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
>
This is somewhat unique to your situtation, due to your file naming.. but
you can probably safely eval the statements prior to execution. Don't quote
the arguments to echo below....
cmds=`echo mv -f ....;
echo mv -f ...;
echo mv -f ...;
echo mv -f ..;
`
echo "$cmds" | sh
>>
>> 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