date issue-find prevoius date in a patricular format

Hi ,

I have written a shell script that takes the current date on the server and stores it in a file.

echo get /usr/home/data-`date '+%Y%d'`.xml> /usr/local/sandeep/GetFILE.ini

I call this GetFILE.ini file from an sftp program to fetch a file from /usr/home/ as location. The file is in this format data-20071115.xml
I have been succesfull in doing this.

This runs froms tuesday to friday. But on Monday i need to fetch Saturday and Sunday file and i don't know how it can be accomplished in this.

Can anyone help

Thanks,
Sandeep

The datecalc script in Perderabo's thread on Date Arithmetic - in the FAQ section
will subtract 1, 2, 3... n days from a date and return a date. So you could get
today - 2 = 20071113

This relies on GNU date.

#!/bin/bash
if [[ $(date +%u) = 1 ]]
then
  echo get /usr/home/data-$(date --date="-2 days" '+%Y%m%d').xml > /usr/local/sandeep/GetFILE.ini
  # some command that calls GetFILE.ini, before it is overwritten.
  echo get /usr/home/data-$(date --date="-1 days" '+%Y%m%d').xml > /usr/local/sandeep/GetFILE.ini
else
  echo get /usr/home/data-$(date '+%Y%m%d').xml > /usr/local/sandeep/GetFILE.ini
fi

You'll find help to this same query in a simple search too.
Key words: previous date

Cheers,
Cameron