creating a file name based on date

I need to automate a weekly process of piping a directory list to a csv file. Normally I do

ls -l > files_04182010.csv (04182010 being the date..)

Can someome show me how I would script this, so that when the script is ran it grabs the current date and formats it and allows me to use that in the name of the .csv file?

Thanks in advance

man man date (POSIX)

mMMDDYYYY=$(date +"%m%d%Y")
ls -l > files_$mMMDDYYYY.csv

This script must also be only ran on Fridays. What is the best way to do that?

I know that i must put an if statement in to check for the date, if it is friday, run it..if it isnt friday..do nothing.

Put it on cron.

We do not have access to cron unfortunately.

weekday=$(date +%w)
if [ $weeday -ne 5 ]
then
    echo "Only run me on fridays"
    exit 1
else
    echo "Arrr, weekend ahead"
fi

Then try this:

mDWeek=$(date +"%a")
if [[ "${mDWeek}" = "Fri" ]]; then
  mMMDDYYYY=$(date +"%m%d%Y")
  ls -l > files_$mMMDDYYYY
fi

This will do it too ...

if [ $(date +%u) != 5 ]; then
  ls -l > files_$(date +"%m%d%Y").csv
fi