Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2012
    Posts
    3

    Unanswered: copy file from one directory to another

    Code:
    echo "inizio copiofatt.sh" > ./elaboro/log.txt
    for filein in `ls ../file_*`
    do
       echo "$filein" >> ./elaboro/log1.txt
       for copia in `cat $filein`
       do
          echo "$copia" >> ./elaboro/log2.txt
          file_da_copiare=`basename $copia`
          echo "$file_da_copiare" >> ./elaboro/log3.txt
          for sposta in `cat listadir`
          do
             if test -f /AOD_NEW/$sposta/$file_da_copiare
             then
                 cp -p /AOD_NEW/$sposta/$file_da_copiare /AOD_NEW/archivio_fatture_plas
    mon
                 if test $? -ne 0
                 then
                     echo "! errore nella copia di $file_da_copiare in /AOD_NEW/$spo
    sta !" >>./elaboro/err.txt
                  else
                     echo "- file $file_da_copiare trovato in /AOD_NEW/$sposta -" >>
    ./elaboro/log.txt
                 fi
             fi
          done
    #   chmod 666 /AOD_NEW/archivio_fatture_plasmon/$copia
       done
       echo "fine elaborazione $filein" >>./elaboro/log.txt
    done
    echo "fine elaborazione" >> ./elaboro/log.txt
    Good morning to all
    My problem is this.
    I wrote a shell that needs to copy from one directory to another one file.
    This is the structure of my fs
    "filein" (filein the variable contains the list of files in a directory. Each file is a pure text documents containing the names of files to copy.)
    This is the content

    file_aaa
    file_aajj
    file_aast
    file_aaaa

    Each of these files contains a list of this type

    / archive/bancoposta/5520466fat898.txt
    / archive/bancoposta/5520467fat899.txt
    / archive/bancoposta/5520468fat900.txt
    / archive/bancoposta/5520469fat901.txt
    / archive/bancoposta/5520470fat902.txt
    / archive/bancoposta/5520471fat903.txt

    "copia" is the variable that contains the name of the file to be copied.

    The files are located in an "fs" divided into many directory
    This is the list of the "fs"

    drwxr-xr-x 2 root system 9029632 Aug 24 2011 2001 -01
    drwxr-xr-x 2 root system 6024192 Aug 24 2011 2001 -02
    drwxr-xr-x 2 root system 8518656 Aug 23 2011 2001 -1
    drwxr-xr-x 2 root system 603136 Jul 23 2011 2001 -10
    drwxr-xr-x 2 root system 594944 Jul 23 2011 2 001 -100
    drwxr-xr-x 2 root system 30720 Aug 24 2011 2001 -1000

    The list of these directories is contained in the variable "sposta"


    My shell has to open the files one at a time of the variable "filein"
    Take the name of the file contained in the variable "copia"
    Look in every directory of the variable "sposta" the file and copy it to the directory

    The shell works well if it finds the first file in the directory of the variable "copia" read all the directories before moving to the next file.
    What's wrong?
    Sorry for my English.
    I use a translator to write.
    thanks
    Carlo

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1

    drwxr-xr-x 2 root system 9029632 Aug 24 2011 2001 -01
    drwxr-xr-x 2 root system 6024192 Aug 24 2011 2001 -02
    drwxr-xr-x 2 root system 8518656 Aug 23 2011 2001 -1
    drwxr-xr-x 2 root system 603136 Jul 23 2011 2001 -10
    drwxr-xr-x 2 root system 594944 Jul 23 2011 2 001 -100
    drwxr-xr-x 2 root system 30720 Aug 24 2011 2001 -1000
    Do these directory names include spaces? Is the first one for example "2001 -01" and the fifth one "2 001 -100"?

  3. #3
    Join Date
    Apr 2012
    Posts
    3
    No no spaces

    I copied and pasted wrong
    no space

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Is it possible for a $file_da_copiare to exist in more than one directory? If so, should the search loop "for sposta in `cat listadir`" exit as soon as a file is found, or should the last one found be the only valid one?

  5. #5
    Join Date
    Apr 2012
    Posts
    3
    no, a single file in each directory.
    I do not know how to change the cycle to release the shel when it finds a file

  6. #6
    Join Date
    Oct 2011
    Posts
    3
    i think instead of this much loop.

    VAR=` find ${DIRECTORY} -name ${FILE} -print`
    cp ${VAR} ${DESIRED_DIRECTORY}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •