Help with bash scripts

Help with bash scripts

Post by Tim Kel » Mon, 27 May 2002 01:45:35



Hi I am a newbie trying to make a script to backup a given file. All I
want to do is copy a given file to a /usr/backups directory however I
need to rename the file so that it doesn't over-write a previous
backup. I think either a random number or the date and time appended
to the filename would do the trick... but the problem is the date and
time returned by the OS contains :'s and /'s and spaces which are not
allowed.

I confess I am actually using Cygwin under windows! I am using Cygwin
because Microsoft batch files I beleive don't even have the power to
do something even this simple!

Any help appreciated,

Cheers Tim

 
 
 

Help with bash scripts

Post by Tataye » Mon, 27 May 2002 02:10:28


Quote:> Hi I am a newbie trying to make a script to backup a given file. All I

Easy :-)

Quote:> want to do is copy a given file to a /usr/backups directory however I
> need to rename the file so that it doesn't over-write a previous

man date --> look at the "s" directive it gives seconds since 01/01/1970 ;-)

Quote:> backup. I think either a random number or the date and time appended
> to the filename would do the trick... but the problem is the date and
> time returned by the OS contains :'s and /'s and spaces which are not
> allowed.

awk ...

Quote:> I confess I am actually using Cygwin under windows! I am using Cygwin
> because Microsoft batch files I beleive don't even have the power to
> do something even this simple!

Even tried?

Quote:> Any help appreciated,

> Cheers Tim

Tatayet

 
 
 

Help with bash scripts

Post by William Par » Mon, 27 May 2002 03:48:19



> Hi I am a newbie trying to make a script to backup a given file. All I
> want to do is copy a given file to a /usr/backups directory however I
> need to rename the file so that it doesn't over-write a previous
> backup. I think either a random number or the date and time appended
> to the filename would do the trick... but the problem is the date and
> time returned by the OS contains :'s and /'s and spaces which are not
> allowed.

> I confess I am actually using Cygwin under windows! I am using Cygwin
> because Microsoft batch files I beleive don't even have the power to
> do something even this simple!

> Any help appreciated,

> Cheers Tim

'man date', particularly '%' format.  Eg.
    date '+%y-%j'
gives you
    02-145
where '02' is year 2002 and '145' is 145th day of the year.

--

8-CPU Cluster, Hosting, NAS, Linux, LaTeX, python, vim, mutt, tin