From owner-freebsd-questions Tue Aug 20 8:18: 3 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3B0DD37B400 for ; Tue, 20 Aug 2002 08:17:58 -0700 (PDT) Received: from clunix.cl.msu.edu (clunix.cl.msu.edu [35.9.2.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7730743E3B for ; Tue, 20 Aug 2002 08:17:57 -0700 (PDT) (envelope-from jerrymc@clunix.cl.msu.edu) Received: (from jerrymc@localhost) by clunix.cl.msu.edu (8.11.6+Sun/8.11.6) id g7KFHNA09296; Tue, 20 Aug 2002 11:17:23 -0400 (EDT) From: Jerry McAllister Message-Id: <200208201517.g7KFHNA09296@clunix.cl.msu.edu> Subject: Re: A simple Shell script Question || Printing the date in a file name To: met@uberstats.com (MET) Date: Tue, 20 Aug 2002 11:17:22 -0400 (EDT) Cc: mpd@rochester.rr.com ('mpd'), freebsd-questions@FreeBSD.ORG ('freebsd-questions-en') In-Reply-To: <001c01c24857$5a563930$6901a8c0@SURVIVAL> from "MET" at Aug 20, 2002 10:39:02 AM X-Mailer: ELM [version 2.5 PL2] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > > Got it -- thanks. > > ~ Matthew > > -----Original Message----- > From: mpd [mailto:mpd@rochester.rr.com] > Sent: Tuesday, August 20, 2002 10:23 AM > To: MET > Cc: 'freebsd-questions-en' > Subject: Re: A simple Shell script Question || Printing the date in a > file name > > > On Tue, Aug 20, 2002 at 10:17:23AM -0400, MET wrote: > > I have a simple shell script that archives and compresses the output > > of a PHP script and then moves it to another location. However, every > > > time it runs it replaces the backup that was previously there. So > > naturally to keep this from happening the file names have to be > > different. So I wanted to print the date in a file name. For example > > > > filename-8-20-2002.tar.bz2 > > > > So how might I do that? > > > > I'm archiving/compressing like this - and that's when I'd like the > > date to be appended to the name. > > > > tar cjf Gunks-{insert date}.tar.bz2 Gunks.txt > > something like this should work: > > #!/bin/sh > > BAK=Gunks-`date "+%m-%d-%Y"`.tar.bz2 > tar cjf $BAK Gunks.txt Of course moving the year to the front makes it sort nicer in a listing eg. Descending by year, then month, then day. BAK=Gunks-`date "+%y-%m-%d"`.tar.bz2 and uppercase 'Y' gets a four digit year as in: BAK=Gunks-`date "+%Y-%m-%d"`.tar.bz2 Enjoy, ////jerry > > > > > ~ Matthew > > > > mike > -- > ___________________________________________________________ > > "IT IS A GOOD THING WE ESCAPED FROM THE OZONE LAYER!!!!!!!" > - Pokey the Penguin from "POKEY THE HIS FRIENDS" > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message