Count the number of files copied from source to destination location


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count the number of files copied from source to destination location
# 8  
Old 07-23-2015
Code:
if [ -d $dest_dir ]; then
 for FILE in `ls $src_dir{$fn,*/$fn}`
 do
  cp /home/oracle/arun/IRMS-CM/{$fn,*/$fn} /home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct
  if [[ $? -eq 0 ]]; then
   ((Succ_Cnt++))
  else
   ((Err_Cnt++))
  fi
 done
 
 if [[ ${Succ_Cnt} -ge 1 ]]; then
  echo "Successfully copied files = ${Succ_Cnt}"
 fi
 
 if [[ ${Err_Cnt} -ge 1 ]]; then
  echo "Failures = ${Err_Cnt}"
 fi
else
 echo "$dest_dir Directory Does not Exist" 
fi

# 9  
Old 07-30-2015
Hello SriniShoo,

Can you explain code we con't count succ_count and error count using below code
can you correct my code
Code:
src_dir="/home/oracle/arun/IRMS-CM"
dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc"
for FILE in $src_dir/{$fn,*/$fn}
do
if [ -d $dest_dir ]; then
if [ -d $dest_dir/$pc ]; then
  if [ -d $dest_dir/$pc/$ct ]; then   
  if [ -f $FILE ];then
     cp $FILE $dest_dir/$pc/$ct && ((Succ_Cnt++)) || ((Err_Cnt++))
fi    
else
echo "$dest_dir/$pc/$ct not exists"
fi
 elif [ -d $dest_dir/$ct ];then
 cp $FILE $dest_dir/$ct && ((Succ_Cnt1++))
fi
else
echo "$dest_dir/$pc/$ct not exists"
fi
done
done< XmlDataNew.txt 
Succ=$[$Succ_Cnt1+$Succ_Cnt]
echo "Succ=$Succ"
echo $Err_Cnt

any body correct and clarify my doubt

how to count successfully fully copied files from source to target location
else error_count if directory not exist or file not exist at source location.
i want below manner
Code:
successcount=10 (out of 15)
error count=5(out of 15)
 or
successcount=15(out of 15)
error_count=0

# 10  
Old 07-30-2015
There's a done too many, and I'm not sure your if ... fi constructs are correctly built. Use a more intuitive, talking indentation and check the logical flow. And, why do you use two Succ_Cnt variables in lieu of incrementing just one on success? And, shouldn't Err_Cnt be incremented if no copy is done as the dest_dir doesn't exist?
# 11  
Old 07-30-2015
Hi RudiC...

actually i'm using count as successfully copied files for directory exist and not exist position purpose...because i have problem with
destination path.....
source path files in current folder and with in folders....
so while coping files from source directory to destination directory..
check with source files and copying files from source to destination as well as how many files copied successfully count & remaining files not copied successfully information important.
error count if directory not exist destination path and file not exist at source location..

count error_count

i want below manner
Code:
src_dir="/home/oracle/arun/IRMS-CM"
dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct"
if [ -d $dest_dir ]; then
for FILE in $src_dir/{$fn,*/$fn}
      do
if [ -f $FILE ];then
    cp $FILE $dest_dir && ((Succ_Cnt++)) || ((Err_Cnt1++))
fi    
done
else
echo " $dest_dir  directory Does Not exists!" >> Test4.txt
Err_Cnt=$(wc -l<Test4.txt)
fi
done< XmlDataNew.txt

please check above my code and replay any one
# 12  
Old 07-30-2015
Not sure I understand... did you run that code snippet? What error msgs were printed? There's again one done too many. And, the dest_dirwould "not exist" exactly once, no matter how many files you want to copy there, so does counting the lines in Test4.txt really make sense?
# 13  
Old 07-30-2015
Using TUI, this would be my apporach (untested, idh oracle):

Code:
....
touch copy.log
...
while read -r fn dc pc ct REST
do dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct"
	tui-bol-dir "$dest_dir" || (echo "$dest_dir does not exist.. skipping.." >> copy.log ; continue )
	echo "--- $dc/$pc/$ct ----" >> copy.log
	tui-cp "$src_dir{$fn,*/$fn}" "$dest_dir" >> copy.log
	echo  >> copy.log
done<XmlDataNew.txt

When done, you can mail the copy log, and will not only see a list of files copied, but also each of which file has been copied successfull or not.

hth
# 14  
Old 07-31-2015
hi All, Any one answer my requirement.
I have source location
Code:
src_dir="/home/oracle/arun/IRMS-CM"

My Target location
Code:
dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct"

my source text files check with below example.text file content
Code:
$fn      "\t"   $dc     "\t"     $pc     "\t"  $ct
file1.doc       US             SANZA         ENCLOSRE
FILE2.DOC    CA                                SUPER
FILE3.DOC    DA              SLIDE          SAVE
FILE4.DOC    SA                                 DOC

the above text file is source text file check with source location files and destination location files.
if i copied files from source to destination location then
files copied successfully then count successfully copied =?
if files not copied successfully count Error files not copied=?
(cause of error if destination folders not exist and source file not exist at source location)
in above source txt file while coping files to destination respective folders
Code:
ex; file1.doc---> $dc/$pc$ct
                  us/sanza/enclosure(file1.doc in enclosure folder )

as well as
Code:
ex; file2.doc -->$dc/$pc$ct
                         CA/ /SUPER(file2.doc in super folder directly if $pc flolder not exist then copy to $ct folder)


I developed below code

Code:
IFS=$'\n'
while read -r line; do
fn=$(echo $line |awk -F "\t" '{print $1}')
dc=$(echo $line |awk -F "\t" '{print $2}')
pc=$(echo $line |awk -F "\t" '{print $3}')
ct=$(echo $line |awk -F "\t" '{print $4}')
src_dir="/home/oracle/arun/IRMS-CM"
dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct"
if [ -d $dest_dir ]; then
for FILE in $src_dir/{$fn,*/$fn}
      do
if [ -f $FILE ];then
    cp $FILE $dest_dir && ((Succ_Cnt++)) || ((Err_Cnt1++))
fi    
done
else
echo " $dest_dir  directory Does Not exists!" >> Test4.txt
Err_Cnt=$(wc -l<Test4.txt)
fi
done< example.txt

please correct that code
count the successfullycopied files and error files count if not copied successfully
while using above code i'm unable to copy the files to $ct folder if $pc folder not exist then it shows error,but i need to copy files from source location to $ct if $pc folder not exist then jump to $ct folder
another issue is errorfiles count(we are not able to count suucessfully copied count and error files not copied files count at a once time with check from source location according example.txt file)
note :
No need to create destination folder if folders not exist at destionation just print cause of error in another error.txt file
then we check error.txt file and create folders manually.


Please suggest and help for in this code and replay with new code
coping files to source location if files copied successfully copied then count number of files counted and error files not copied successfully count
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Open ports from source to destination

Is there a way to find out all the ports open between source IP & destination IP in any way ? (12 Replies)
Discussion started by: UnknownGuy
12 Replies

2. UNIX for Dummies Questions & Answers

How to move gz files from one source directory to destination directory?

Hi All, Daily i am doing the house keeping in one of my server and manually moving the files which were older than 90 days and moving to destination folder. using the find command . Could you please assist me how to put the automation using the shell script . ... (11 Replies)
Discussion started by: venkat918
11 Replies

3. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

4. UNIX for Dummies Questions & Answers

How to count number files successfully copied from source to target location?

Hi Guys, how to count number of files successfully copied while coping files from source to destination path ex:10 files from source to target location copying if 8 files copied successfully then echo successfully copied=8 failure=2 files if two files get error to coping files... (2 Replies)
Discussion started by: sravanreddy
2 Replies

5. Post Here to Contact Site Administrators and Moderators

How to count successfully copy files source to target location with check directory in Linux?

Hi guys...please any one help me .... how to copy files from source to target location if 5 files copied successfully out of 10 files then implement success=10 and if remaining 5 files not copied successfully then count error=5 how to implement this condition with in loop i need code linux... (0 Replies)
Discussion started by: sravanreddy
0 Replies

6. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

7. Linux

rpmbuild, how to specify a different source and destination path for files

I'd like to specify a different build and deployment path for files, by default the same path is used for both build and install, I wasn't able to find a way to make these different. With Solaris pkgadd, one can specify different paths in prototype, so I would assume something like that is possible... (0 Replies)
Discussion started by: tiburblium
0 Replies

8. Shell Programming and Scripting

Move all files from source to destination directory based on the filename

Move all files starting with a specific name to different directory. This shell script program should have three parameters File Name Source Directory Destination Directory User should be able to enter ‘AB_CD*' in file name parameter. In this case all the files starting with AB_CD will... (1 Reply)
Discussion started by: chetancrsp18
1 Replies

9. Shell Programming and Scripting

Moving extremely large number of files to destination

Hello Techies, m here with a small issue. Have read out all the relavent threads on unix.com but it was not so good sol. for me. It's a simple & known issue. I want to move lots of files to dest folder. Actually I want to pick up 1 year older files, but that is even taking lots of... (16 Replies)
Discussion started by: kedar.mehta
16 Replies

10. Shell Programming and Scripting

Count total unique destination for source

Hi, need help how to count unique destination for the source ip. The file is contains 4 number of fields. Example of the file is here src ip dest ip #of flows total bytes 192.168.6.0 88.0.33.2 12 128 192.168.6.0 88.0.33.2 1 168 192.168.6.0 ... (5 Replies)
Discussion started by: new_buddy
5 Replies
Login or Register to Ask a Question