1

I've created a script wherein it will compare the two files in different directory (rpms and newrpms). This two directory composed of files. in the rpms/ side it was the old version files and in the newrpms/ is the updated ones. So in this script, the main goal for this is that the files inside the directory will be compared, if there are same name files remove the older one and replace it with the updated file.

rpms/ -- the files inside of this directory

firefox-24.5.0-1.el5_10.i386.rpm
firefox-24.5.0-1.el5_10.x86_64.rpm
java-1.6.0-openjdk-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.6.0-openjdk-demo-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.6.0-openjdk-devel-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.6.0-openjdk-javadoc-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.6.0-openjdk-src-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.7.0-openjdk-1.7.0.55-2.4.7.1.el5_10.x86_64.rpm
java-1.7.0-openjdk-debuginfo-1.7.0.55-2.4.7.1.el5_10.x86_64.rpm
java-1.7.0-openjdk-devel-1.7.0.55-2.4.7.1.el5_10.x86_64.rpm
java-1.7.0-openjdk-javadoc-1.7.0.55-2.4.7.1.el5_10.x86_64.rpm

newrpms/ -- the updated files that needs to replace the old ones in the rpms/ directory

firefox-25.5.0-1.el5_10.i386.rpm
firefox-25.5.0-1.el5_10.x86_64.rpm
java-1.6.0-openjdk-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.6.0-openjdk-demo-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.6.0-openjdk-devel-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.6.0-openjdk-javadoc-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm
java-1.6.0-openjdk-src-1.6.0.0-5.1.13.3.el5_10.x86_64.rpm

Please see belows script.

for i in $(\ls -d ./rpms/*);
do diff ${i} newrpms/; 
done

For the code above, nothing happens. Can anyone help me to solve my problem. All I want is to compare the two directory and get the the same files if and only if in the rpms/ directory don't have the same files that newrpms/ have it is very understandable to move it from the newrpms/ to rpms/ nad if ever that they have the same filename but have just little part are not the same. Check it the most updated one. ex.

firefox-24.5.0-1.el5_10.i386.rpm --> in the rpms/
firefox-25.5.0-1.el5_10.i386.rpm --> in the newrpms/

so the most updated one is in the newrpms/. remove the firefox-24.5.0-1.el5_10.i386.rpm in the rpms/ and move the firefox-25.5.0-1.el5_10.i386.rpm into rpms/

Biffen
  • 6,249
  • 6
  • 28
  • 36

1 Answers1

1

It's difficult to know what is going wrong with your script. Are you sure there are differences between the rmps in the new and old directory? Have you tried the -s option for diff that will report identical files?

But in any case, the script is too complicated for the task you are trying to perform. This should be the equivalent command:

diff rpms newrpms

If there are files in one directory that do not exist in the other, that will be noted in the output. And differences in binary files will also reported. But you probably don't even need to do that. Why not use the cp command to simply copy files from newrpms to rpms? Or, if you want to be more sophisticated, use rsync:

rsync -av newrpms rpms

That will check to see if any file in newrpms is newer than the one in rpms and only perform the copy when needed. (Check out man rsync for more details.)

Jon 'links in bio' Ericson
  • 20,880
  • 12
  • 98
  • 148