Script to Backup files

Hi,

I wrote a simple script to backup of index.php and index.html in my box. So, I wrote a script which take a copy of the index page as 1Mar09: but it does not comes up..

#! /bin/bash
find . -name index.* > domains.txt
for i in `cat domains.txt` ; do cp index* index*.1Mar09 $i; done
But it gives a error message as :

cp: copying multiple files, but last argument `./kla/index.php' is not a directory
Try `cp --help' for more information.
cp: copying multiple files, but last argument `./kla/index.html' is not a directory
Try `cp --help' for more information.
cp: copying multiple files, but last argument `./n/index.php' is not a directory
Try `cp --help' for more information.

Please give a exact script and let me know where I am wrong?

#!/bin/bash

for i in `find . -name "index.*"`
do
    cp $i $i.1Mar09;
done

Quote the pattern:

find . -name 'index.*' > domains.txt

That will fail if any of the filenames in domains.txt contain spaces. Use a while loop to read from the file:

while IFS= read -r i
do
  ....
done < domains.txt

Or just pipe the output of find into your loop:

find . -name 'index.*' |
while IFS= read -r i

That line is nonsense. The syntax for cp is:

cp file destination

Or:

cp file file ...  directory

Thank you candlejack, the scripts comes up... Thanks a lot.
And a special thanks to cfajohnson...

Hi,

One more help, I need a script to remove 60 lines at the bottom of the file and need to add two more line at the bottom as </body> </html>

file=/path/to/file ## adjust to taste
lines=$( wc -l < "$file" )
{
  head -n$(( $lines - 60 )) "$file"
  printf "  </body>\n</html>\n"
} > tempfile && mv tempfile "$file"

(You needn't add those two lines. Without them, the file will still be valid HTML.)

Thanks a lot.. That worked out very well...
Thank you.l... cfajohnson