Time/date manipulation

Time/date manipulation

Post by Andrew Clar » Wed, 13 Jun 2001 18:35:27



Just a quick question, hope you might know the answer. I have setup a script
which will backup the Unix box every night (hostdump.sh). Now the backup
works fine, and part of it writes stdout & stderr from the script to a
logfile, which will take the following format:

/backuplogs/tigger.DevRmt0n.Level0.12.06.2001

/backuplogs - being the directory in which the logs will reside

tigger - the server name

DevRmt0n - the tape device


12.06.2001 - the date of backup

Now to invoke a backup, the following command is run:

# hostdump.sh 0 /dev/rmt/0n /backuplogs/tigger.Dev.Rmt0n.Level0.12.06.2001
tigger

I want to put this in a cron job, which I know how to do. However, the trick
is that I need to put some form of date manipulation within the cron job, so
that the backuplog name will reflect the date on which the backup is
executed. Do you have any ideas, on how I could achieve this.

Look forward to your response.

Andrew Clark

 
 
 

Time/date manipulation

Post by Steve Bellen » Wed, 13 Jun 2001 20:56:43




>Just a quick question, hope you might know the answer. I have setup a script
>which will backup the Unix box every night (hostdump.sh). Now the backup
>works fine, and part of it writes stdout & stderr from the script to a
>logfile, which will take the following format:

>/backuplogs/tigger.DevRmt0n.Level0.12.06.2001

>/backuplogs - being the directory in which the logs will reside

>tigger - the server name

>DevRmt0n - the tape device


>12.06.2001 - the date of backup

>Now to invoke a backup, the following command is run:

># hostdump.sh 0 /dev/rmt/0n /backuplogs/tigger.Dev.Rmt0n.Level0.12.06.2001
>tigger

>I want to put this in a cron job, which I know how to do. However, the trick
>is that I need to put some form of date manipulation within the cron job, so
>that the backuplog name will reflect the date on which the backup is
>executed. Do you have any ideas, on how I could achieve this.

>Look forward to your response.

BACKUPFILE=/<path>/`/bin/date "+%Y-%m-%d"`

Will make $BACKUPFILE be /<path>/2001-06-12 or whatever the current date is.
--
http://www.math.fsu.edu/~bellenot
bellenot <At/> math.fsu.edu
+1.850.644.7189 (4053fax)

 
 
 

Time/date manipulation

Post by Jay Lesse » Thu, 14 Jun 2001 01:00:27



> # hostdump.sh 0 /dev/rmt/0n /backuplogs/tigger.Dev.Rmt0n.Level0.12.06.2001
> tigger

> I want to put this in a cron job, which I know how to do. However, the trick
> is that I need to put some form of date manipulation within the cron job, so
> that the backuplog name will reflect the date on which the backup is
> executed. Do you have any ideas, on how I could achieve this.

Have hostdump.sh do it's own logfile name instead of trying to pass it
in, and use the date(1) +format feature to build the date part of the
file name.  Here's an example from one of my scripts:

    LOGFILE=${LOGDIR}/log.`date '+%Y%m%d-%H:%M'`

which makes a name like "log.20010612-08:58".  For your own sanity, please
make it year-month-day instead of the other way 'round, so it sorts properly.

-Jay-