Register
It is currently Fri Apr 25, 2014 3:21 am

Request for script to copy files to the other folder(...)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Mar 30, 2008 11:05 am   

Joined: Sun Mar 30, 2008 10:51 am
Posts: 2
Im new in the community and I want to write script to copy files from one dir to another. Im doing function with parametres
up - copying all content of dir 1 to 2 but im copying only newer files - have latest modification date then 2nd file
commit - same as above but from folder 2 to folder 1
status - showing info about files - if there are same files in 1 dir and 2 dir or what file is newer

I've been searching for this script and found similar but i dunno how to make it working in my case:
http://bashscripts.org/viewtopic.php?t= ... urce+files

As I said Im new in it and Bash is for me like chinesse:P I was programming only in C and C++. Thx for all replies!


Top
 Profile  
 PostPosted: Fri Apr 04, 2008 11:20 am   

Joined: Sun Mar 30, 2008 10:51 am
Posts: 2
thx for helping.. Anyways for future ill give here answer:

Code:
#!/bin/sh
DIR1="/home/11111/sys/makefile2"
DIR2="/home/11111/sys/bank2"

_copy()
{

for FILE1 in $1/*; do
   FILE="`basename $FILE1`"
   FILE2="$2/$FILE"

       if [ -d $FILE1 ]; then
               TEMP=`echo $1/$FILE`
               _copy
       fi

       if [ ! -d "$FILE1" ]; then
         
               if [ "`find $2 -name $FILE`" ]; then
         for FILE3 in `find $2 -name $FILE`; do

                                   cp -u $FILE1 $FILE3 2>/dev/null
         done

                   else
                       cp $FILE1 $FILE2 2>/dev/null

               fi
       

       fi

done

}

_status()
{
       for FILE in $1/*;do
       FILE1="`basename $FILE`"

               if [ -d $FILE ]; then
                       _status $FILE $2 11
               fi #END -d1

               if [ ! -d $FILE ]; then

                       if [ "`find $2 -name $FILE1`" ]; then


                               for DATE1 in $2/*; do
                                 DATE2="`basename $DATE1`"

                                 if [ $DATE2 == $FILE1 ]; then

                                       SAVE="$DATE1"
                                       SAVE2="$DATE2"
                                 fi

                                 done #END for date1


                               if [ $FILE1 == $SAVE2 ]; then
                               if [ "`diff -q $FILE $SAVE 2>/dev/null`" !='' ]; then 
                                       echo "[NewVer]$FILE"

                               fi
                               fi


                               else
                             

                               if [ $3 -eq "1" ] || [ $3 -eq "11" ]; then
                                       echo "[Dir1]$FILE1"
                                       else
                                               echo "[Dir2]$FILE1"
                               fi

                               

                       fi


               fi

       done


   if [ $3 -eq "1" ]; then

   for FILE4 in $2/*; do
   FILE5="`basename $FILE4`"

               if [ ! -d $FILE4 ]; then

                       if [ ! "`find $DIR1 -name $FILE5`" ]; then
                                echo "[Dir2]$FILE5"
                       fi
               fi

               if [ -d $FILE4 ]; then
                       _status $FILE4 $1 00
               fi

   done

   fi
}

case $1 in
   "up") _copy $DIR1 $DIR2;;
   "commit") _copy $DIR2 $DIR1;;
   "status") _status $DIR1 $DIR2 1;;
   "help")
           echo "[Dir1]FILE - FILE is in$DIR1"
           echo "[Dir2]FILE - FILE is in $DIR2"
           echo "[NewVer]FILE - newer version of file";;
   *) echo 'Wrong parameter'; exit;;
esac


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP