Copy Files with script

Hello,

I have written a script to copy files from one partion to another. Not sure if this is correct.

#!/bin/sh

CDR_SOURCE=/storage/archive/logmgmt/result/billing/
CDR_DEST=/storage4/archive/logmgmt/result/billing/

cp $CDR_SOURCE $CDR_DEST;

exit 0

The CDR_SOURCE folder has 98% .csv files and few text files. i need to copy all these to CDR_DEST

Please correct me if i m wrong. Thanks

-Siddhesh.K

---------- Post updated at 09:20 PM ---------- Previous update was at 08:58 PM ----------

i just modified this.

#!/bin/sh

CDR_SOURCE=/storage/archive/logmgmt/result/billing/*
CDR_DEST=/storage4/archive/logmgmt/result/billing/

while read sourcefile destfile
do
cp -arp $CDR_SOURCE $CDR_DEST

if [ $? -eq 0 ] ; then
         echo "$CDR_DEST copied successfully from $CDR_SOURCE"
      else
         echo  "ERROR: failed to copy $CDR_DEST from $CDR_SOURCE"
fi
done < /home/xmp/cdrcopy.log

Will this work? Please adive.

-Siddhesh.K

Why don't you run it and let us know if it works? It won't crash your computer if it doesn't.

In any case, wouldn't it be simpler to just run cp -r /source /destination ?

I don't think so!

Inside the while loop you are using "static" variables: CDR_SOURCE and CDR_DEST. Maybe you want this:

#!/bin/sh

CDR_SOURCE=/storage/archive/logmgmt/result/billing/*
CDR_DEST=/storage4/archive/logmgmt/result/billing/

while read sourcefile destfile
do
cp -arp "${sourcefile}" "${destfile}"
if [ $? -eq 0 ] ; then
         echo "[${destfile}] copied successfully from [${sourcefile}]"
      else
         echo  "ERROR: failed to copy [${destfile}] from ["${sourcefile}"]"
fi
done < /home/xmp/cdrcopy.log

I know this would work.

But i need run logs that it actually copied files. You know Clients sometimes demad things which does not really make any sense.

Anyways, will my script work?

-Siddhesh.K

My opinion may not be important to you: I think your script works, but it makes no sense (as I commented above) and I can't understant why you can't say it to your "client"!

As verdepollo commented, test it and you will know if it works or not, as expected!

Thanks felipe.vinturin

Your code looks more promising to me. I shall use the same.

Appreciate your help.

-Siddhesh