Operating System - HP-UX
1753876 Members
7431 Online
108809 Solutions
New Discussion

critical Files comparison on to different path & copying

 
Vishal_1980
Regular Advisor

critical Files comparison on to different path & copying

Hello expert,

 

We have below path on the UNIX box ,

 

/home/accpd/tobleer/ssp8install/lsoct/patches  & /lya/c1s2d6/ranson/var/install/PORTAL/patches

 

There are few files on the first path & second path as well. I need to compair all the files.

My porblem is i need to compair the files on both the path & need to copy files which are not mention under the second path  from the first path .There are more than 30 to 80 fileson both the path , below are the output....

 

/home/accpd/tobleer/ssp8install/lsoct/patches  $ ls -l
total 305066
-rwxrwxrwx    1 tobleer accpd         502787 Aug 18 17:31 lsoct_AIX61_09000111P18646.zip
-rwxrwxrwx    1 tobleer accpd         502598 Aug 18 17:31 lsoct_AIX61_09000111P19282.zip
-rwxrwxrwx    1 tobleer accpd         496631 Aug 18 17:31 lsoct_AIX61_09000111P19682.zip
-rwxrwxrwx    1 tobleer accpd         575693 Aug 18 17:31 lsoct_AIX61_09000111P20477.zip
-rwxrwxrwx    1 tobleer accpd         500371 Aug 18 17:31 lsoct_AIX61_09000111P20959.zip
-rwxrwxrwx    1 tobleer accpd         494793 Aug 18 17:31 lsoct_AIX61_09000111P22491.zip
-rwxrwxrwx    1 tobleer accpd         786346 Aug 18 17:31 lsoct_AIX61_09000111P22748.zip
-rwxrwxrwx    1 tobleer accpd        4261294 Aug 18 17:31 lsoct_AIX61_09000111P23912.zip
-rwxrwxrwx    1 tobleer accpd         496464 Aug 18 17:31 lsoct_AIX61_09000111P23993.zip
-rwxrwxrwx    1 tobleer accpd       17797402 Aug 18 17:31 lsoct_AIX61_09000111P26740.zip
-rwxrwxrwx    1 tobleer accpd         496425 Aug 18 17:31 lsoct_AIX61_09000111P28066.zip
-rwxrwxrwx    1 tobleer accpd      131104868 Aug 18 17:31 lsoct_AIX61_09000111P28645.zip

 

&

 

lya/c1s2d6/ranson/var/install/PORTAL/patches $ ls -l
total 4352
-rw-rw-rw-    1 root     ranson      548336 Feb 14 2013  XML_09000111P19534.jar
-rw-r-----    1 root     system       506313 Jan 15 2013  XML_09000111P19534.zip
-rw-rw-rw-    1 root     ranson     605262 Feb 14 2013  XML_09000111P19654.jar
-rw-r-----    1 root     system       563534 Jan 15 2013  XML_09000111P19654.zip

 

 

Always i need to compair the files both the location & need to copy those files which are not present in the below

 

lya/c1s2d6/ranson/var/install/PORTAL/patches

 

Can i do this using the script comparing the files from both the location & copying the file from the first location to the second location which are not present in the second location ..

 

Thanks & regards,

Vishal

12 REPLIES 12
Patrick Wallek
Honored Contributor

Re: critical Files comparison on to different path & copying

The tool 'rsync' is built precisely for this type of task.

 

rsync will check the files in each directory and determine what needs to be done to make the destination directory the same as the source.

 

In its most basic form, this will sync the source and the destination directories:

 

# rsync -av /home/accpd/tobleer/ssp8install/lsoct/patches/  /lya/c1s2d6/ranson/var/install/PORTAL/patches/

 

There are numerous options to rsync that will allow you to do numerous things, one of which is to remove files from the destination directory if the are removed from the source directory.

 

 

Vishal_1980
Regular Advisor

Re: critical Files comparison on to different path & copying

Thanks Patrick,

However we have to do this for HP-UX & AIX as well.
For HP-UX it will work , can you please suggest for AIX as well.
As its a need for the production.
Patrick Wallek
Honored Contributor

Re: critical Files comparison on to different path & copying

rsync is available for AIX as well.

 

http://www.perzl.org/aix/index.php?n=Main.Rsync

Vishal_1980
Regular Advisor

Re: critical Files comparison on to different path & copying

can you provide me such script so that the whole process will get automate as tallying & copying files is the time consuming task.
And there are more than 80 files on each of the path.I just need that the files from the first & second path will be tallied out & the file which are missing in the second path will be copied from the first path.
Dennis Handly
Acclaimed Contributor

Re: critical files comparison on to different path & copying

>I need to compare all the files.

 

Compare the just names or also the content?

 

>can you provide me such script so that the whole process

 

Doesn't Patrick's one line work for you?

rsync -av /home/accpd/tobleer/ssp8install/lsoct/patches/  /lya/c1s2d6/ranson/var/install/PORTAL/patches/

Vishal_1980
Regular Advisor

Re: critical Files comparison on to different path & copying

Hello Dennis sir,

Just the name not the content ...

Thanks
Vishal
Dennis Handly
Acclaimed Contributor

Re: critical files comparison on to different path & copying

>Just the name not the content

 

I think rsync's job is to copy the data.

Vishal_1980
Regular Advisor

Re: critical files comparison on to different path & copying

Hello Dennis sir ..

Let me put in a simple way ....
Suppose on the first path there are files namely : a , b , c , d , e , f & g & on the second path there are files namely a,c ,e,& g ...Now here i want to tally the files ( & i am talking about 80 files aprox) now i want to copy the missing files from first path to second path...i.e file b , d & f ...
Patrick Wallek
Honored Contributor

Re: critical files comparison on to different path & copying

Since you seem to not want to use rsync (though I don't understnad why...), here is a script that will compare 2 directories and  copy whatever the files that exist in DIR1 but not in DIR2 from DIR1 to DIR2.

 

# cat test.sh

#!/usr/bin/sh

DIR1=/tmp/test1
DIR2=/tmp/test2
TMP1=/tmp/dir1.$$
TMP2=/tmp/dir2.$$

/usr/bin/ls -1A ${DIR1} > ${TMP1}
/usr/bin/ls -1A ${DIR2} > ${TMP2}

while read FILE
do
grep -q ^${FILE}$ ${TMP2}
EXIST=$?
if (( ${EXIST} != 0 )) ; then
  echo "Copying ${DIR1}/${FILE} to ${DIR2}"
  cp -p ${DIR1}/${FILE} ${DIR2}
fi
done < ${TMP1}
rm ${TMP1} ${TMP2}

 

Modify the DIR1 and DIR2 directory variables to suit your needs.

 

Here is what my DIR1 and DIR2 looked like BEFORE I ran the script:

# ll /tmp/test1 /tmp/test2

/tmp/test1:
total 16
drwxr-xr-x   2 root       sys             96 Sep  4 13:57 .
drwxrwxrwt  10 root       root          8192 Sep  4 14:32 ..
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file1
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file3
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file5
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file7

/tmp/test2:
total 16
drwxr-xr-x   2 root       sys             96 Sep  4 13:57 .
drwxrwxrwt  10 root       root          8192 Sep  4 14:32 ..
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file1
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file7

 

 

Here is what they looked like after I ran the script:

# ll /tmp/test1 /tmp/test2

/tmp/test1:
total 16
drwxr-xr-x   2 root       sys             96 Sep  4 13:57 .
drwxrwxrwt  10 root       root          8192 Sep  4 14:35 ..
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file1
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file3
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file5
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file7

/tmp/test2:
total 16
drwxr-xr-x   2 root       sys             96 Sep  4 14:35 .
drwxrwxrwt  10 root       root          8192 Sep  4 14:35 ..
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file1
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file3
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file5
-rw-r--r--   1 root       sys              0 Sep  4 13:57 file7

 

 

The first time you run the script I would comment out the 'cp' command so it will just echo the information so you can verify that the script is working correctly.

 

Hopefully this satisfies your needs.