batch file using system date in file name??

batch file using system date in file name??

Post by Jan Grent » Sun, 28 Dec 1997 04:00:00



I've written a batch file that runs on a daily basis. I want it to do the
following:

cp fileDATE.txt tomorrow.txt

I'd like the DATE to be "system date"+1: cp file971225 tomorrow.txt
The date has to be in the format YYMMDD.

Jan

 
 
 

batch file using system date in file name??

Post by Grigoriy Stroki » Sun, 28 Dec 1997 04:00:00


Quote:>cp fileDATE.txt tomorrow.txt

>I'd like the DATE to be "system date"+1: cp file971225 tomorrow.txt
>The date has to be in the format YYMMDD.

cp file$(date +"%y%m%d" -d "+1 day").txt tomorrow.txt

 
 
 

batch file using system date in file name??

Post by Jan Grent » Tue, 30 Dec 1997 04:00:00


I tried it for the following, but got the error "Illegal variable name":

/local/bin/lynx -dump http://www.vg.no/rampelys/vg/html/$(date +"%y%m%d" -d
"+1 day").html

Quote:>>The date has to be in the format YYMMDD.
>cp file$(date +"%y%m%d" -d "+1 day").txt tomorrow.txt

 
 
 

batch file using system date in file name??

Post by Chris Hal » Tue, 30 Dec 1997 04:00:00



> >cp fileDATE.txt tomorrow.txt

> >I'd like the DATE to be "system date"+1: cp file971225 tomorrow.txt
> >The date has to be in the format YYMMDD.

> cp file$(date +"%y%m%d" -d "+1 day").txt tomorrow.txt

'Fraid not, this only works with GNU date and is thus not particually portable.
I have two solutions:

As a frig you can set the timezone variable forwards 24 hours, so mine would be

    TZ=GMT-24BST-25

when the date program is run it will show tomorrow's date. This variable was
never designed for this so I strongly recommend not doing this, or solution two
run the following script (it's probabaly not Y2K compliant)

!/usr/bin/ksh

typeset -i  Y M D

set -A month "" 31 29 31 30 31 30 31 31 30 31 30 31

Y=$(date +"%y")
M=$(date +"%m")
D=$(date +"%d")

D=D+1

if [[ D -gt ${month[M]} || ( M -eq 2 && D -gt 28 && Y%4 -ne 0 ) ]]
then
    D=1
    M=M+1

    if [[ M -gt 12 ]]
    then
        M=1
        Y=Y+1
        if [[ Y -gt 99 ]]
        then
            Y=0
        fi
    fi
fi

printf "%02d%02d%02d\n" $Y $M $D

--
Chris.

 
 
 

batch file using system date in file name??

Post by Bill Thompso » Tue, 30 Dec 1997 04:00:00



> I tried it for the following, but got the error "Illegal variable name":

> /local/bin/lynx -dump http://www.vg.no/rampelys/vg/html/$(date +"%y%m%d" -d
> "+1 day").html

> >>The date has to be in the format YYMMDD.
> >cp file$(date +"%y%m%d" -d "+1 day").txt tomorrow.txt

I didn't catch the original post, but to create a file name with the
current date imbedded, use the "date" command as above, but inclose
in in back-tics:

/local/bin/lynx -dump http://www.vg.no/rampelys/vg/html/`date
+"%y%m%d"`.html

this will expand to:

/local/bin/lynx -dump http://www.vg.no/rampelys/vg/html/YYMMDD.html

where YYMMDD is the current year, month and day

--

 
 
 

1. Using system date-time as file name

Hi:

Could one of you Unix wizards help me here.  What Unix commands does one
use to use the system date-time as a filename via a shell script?  I am
using AIX.

Thanks for any assistance you can provide.

Michael Murphy
===================================================================

            "Distribution & Commerce Systems Solutions"              
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. Where does SIOCGSTAMP come from?

3. Compare file modification date using tcsh built-ins

4. [TRIVIAL] don't let OOM killer kill same process repeatedly

5. Batch Files: Why is it the only the last line of the batch files is executing?

6. x86 SMC EtherPower 8432 support?

7. Enhanced Filing system - file system like DEC Advanced File system for Linux

8. vi.recover

9. File Names and File Dates

10. Mail Status File with the File Name Changes by Date

11. Scripting Help: tar a dir with time and date as file tar file name..................TIA

12. Using date as a file name

13. Archiving files in "date folders" based on date and time file generated