for loop problem

Hi,
I have a directory called logs in which i have the log files.

i have to touch the file before deleting it.

i am doing like this
filestodelete="*.log* *log*"

for files in $filestodelete
do
touch $files $files.$(date +%a)
rm -f $filestodelete
done

touch is not working here,means it is not touching the file before deleting it.
kindly help me out in this.

Hello,

First, when you select "*log*", you don't have to select "*.log*" beacause they are already in the first selection !

Second, why "touching" the file before deleting it ?

Third, your script will be runnig with "unable to remove file xxx" beacause of the command "rm -f $filestodelete" that will delete all the files selected by "for files in (*log*|*.log*)"

So, I propose you the script :

list=$(ls *log*)

for file in $list
do
    cp $file $file.$(date +%a)
    rm -f $file
done

you gave me good suggestions.Thanks..

i have to touch the file because we have some processes running that need to pick that blank file otherwise we need to restart the aaplication again if i deleted the file without touching it.cp will unnecessarily increase the size.

What about moving the file and touching a new one:

for file in `ls *log*`
do
    mv $file $file.`date +%a` && touch $file || echo "Can not backup $file";
done

Thanks for all your replies.

but i got a problem here-- my script is like this--

BackupLocation="$OPTARG"
                if [[ $BackupLocation != *backup ]]; then
                        echo "Appending backup subdirectories"
                        BackupLocation=$BackupLocation/backup
                        mkdir -p $BackupLocation >/dev/null 2>&1
                        if [[ $? != 0 ]];then
                        echo "First Create The Directory And Then Take backup"
                        fi
                        cd $FileLocation
                        pwd
                        cp -R $FilesToDelete $BackupLocation
                       list=$(ls *log*)
                        for files in $list
                        do
                             rm -f $files
                          touch $files.$(date +%a)
                                                 done
                else
                        mkdir -p $BackupLocation >/dev/null 2>&1
                        cp -R $FilesToDelete $BackupLocation
                        for files in $list
                        do
                          rm -f $files
                          touch $files.$(date +%a)
                          
                        done
                if [[ ! -d $BackupLocation ]]; then
                echo "Unable to make backup directory: $BackupLocation"
                        if [[ $IsCronJob -eq 1 ]]; then
                          SendMiddleTierCleanMail "Middletierclean error message" $mt_clean_errfile
                        fi

here it will touch the file again and again and appending the day after the file name again like->
ansrpt26529.log.Fri.Fri.Fri.Fri
but i do not want it like that.
i have to take backup of the file.then touch it and delete the file.
the pattern matching for the files to delete is
list=$(ls *log*)
it is selecting all the files ansrpt26529.log.Fri.Fri.Fri.Fri like this but i do not want it like this it sould be only ansrpt26529.log.Fri.
pattern matching may be diffrent here so give me some suggestions to solve this problem.

What about

                       
list=$(ls *log.???)
for files in $list
do
    rm -f $files
    touch `echo $files | sed 's [^.]*$  '``date +%a`
done