need help using find and date (julian)

I'm trying to put together a little script that will move some files to a directory, uncompress the file then delete the file when processing is complete.

The files are all named using julian date

2009072.Z
2009071.Z
2009070.Z
2009069.Z
2009068.Z
2009067.Z
2009066.Z
2009065.Z
2009064.Z
2009063.Z
2009062.Z
2009061.Z
2009060.Z
2009059.Z
2009058.Z
2009057.Z

each day the oldest file falls off and the next day takes the lead.

I'm trying to find a way that will find the file with todays julian date, cp to another directory, uncompress, run another script on this uncompressed file, delete the file and then return to master directory to copy the next file over.

I can't mass cp the files because of size restrictions so I have to handle each file one at a time.

Thoughts or ideas would be very appreciated.

Thanks!

From today -> files in the past for one year.

cd /someplace
start=$( date +%Y%03j )
stop=$(  date +%Y000 )
while [[ $start -gt $stop ]]
{
     if [[ -f ${start}.Z ]] ; then
       cp ${start}.Z /anotherplace
       my_other_script.sh /anotherplace/${start}.Z
       rm -f /anotherplace/${start}.Z
       start=$(( $start - 1 ))
     else
           echo "${start}.Z not found .. skipping on to the next file "
    fi
}

thanks for the reply but I have a question...

You have
start=$( date +%Y%03j )
stop=$( date +%Y000 )

shouldn't that line actually be
start=$( date +%Y365 )
stop=$( date +%Y000 )

here is what I'm working with now...

cd /cms/ech_data/archive
start=$( date +%Y%j )
stop=$(  date +%Y000 )
while [[ $start -gt $stop ]]
do
    cp ${start}.Z ../recovery
    cd ../recovery
    uncompress ${start}.Z
    cpio -ivm < ${start}
    rm ${start}
    * touch   this is an error also  touch [filename] is the syntax 

for file in `ls chr*`
        do
        /export/home/ech/OA_resend $file
        echo $file
        rm $file
        done
        start=$(( $start - 1 ))
done

this script generates this error
syntax error at line 10 : `while' unmatched

Please see the changes in red.

thanks... I'm still missing something and I can't see what it is...

I'm trying to run the script in debug mode -x but it looks like I need to insert some pauses so I can read what the output is...

How can I pause the script at different points in the script?

never mind.. I think I found what I need....

if I wanted to terminate my script when the following message appears

"No such file or directory"

How would I do that?

this is what I have so far but it bombs out in my if statement...

readOne () {
tput smso
echo "Press any key to return \c"
tput rmso
oldstty=`stty -g`
stty -icanon -echo min 1 time 0
dd bs=1 count=1 >/dev/null 2>&1
stty "$oldstty"
echo
}
tempoutput=`mktemp`
cd /cms/ech_data/archive
start=$( date +%Y%j )
stop=$(  date +%Y000 )
while [[ $start -gt $stop ]]
do
    cp ${start}.Z ../recovery &>tempoutput;
        alloutput=`cat tempoutput`
                if $alloutput = "No such file or directory"
                        then exit
                fi
        readOne
    cd ../recovery
    uncompress ${start}.Z
    readOne
    cpio -ivm < ${start}
    rm ${start}
    touch *
for file in `ls chr*`
        do
        /export/home/pserv/ech/OA_resend $file
        readOne
        echo $file
        rm $file
        done

cd /cms/ech_data_archive
        start=$(( $start - 1 ))
done