[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Generating unique file names
From: |
Chris F.A. Johnson |
Subject: |
Re: Generating unique file names |
Date: |
Sun, 13 May 2007 17:45:46 -0400 |
User-agent: |
slrn/0.9.8.1 (Linux) |
On 2007-05-13, matte wrote:
>
> I am doing a simple [1]backup Bash script that creates a backup archive of
> a
> folder (or file) I am working on.
Where is the script? The link below is to the forums as a whole.
> I want to have snapshaps all saved to one
> directory. To ensure unique name, I am currently appending the date and
> time
> to "MyArcName_data_time." But this creates a long and ugly name. I'd like
> either something cleaner like a unique number appended (based on total
> files
> in directory), or some random temp filename generator function that I don't
> yet know about.
>
> The count would be sufficient, as each folder will always hold ONLY these
> archives, and no hidden files.
> Thus, my directory would be:
> myArcName_1.tar.gz
> myArcName_2.tar.gz
> myArcName_3.tar.gz
> ...
> iF there's some bash function for this, groovy. If not, i just need to know
> how to count the directories from inside my script.
> Thanks in advance
I use this in one script (leave out the date if you prefer):
date=$(date +%Y-%m-%d)
n=
tarfile=wg-$date${n:--$n}.tgz
while [ -f "$tarfile" ]
do
n=$(( ${n:=0} + 1 ))
tarfile=wg-$date-$n.tgz
done
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)