General
cancel
Showing results for 
Search instead for 
Did you mean: 

script that copies upgraded rpms ?

Maaz
Valued Contributor

script that copies upgraded rpms ?

Hi Gurus

i have a directory(old_rpms_dir) that contains some rpms.

I have another directory(new_rpms_dir) that contains all of the rpms that "old_rpm_dir" directory contains, as well as some additional rpms

I want a script that copies only those rpms from new_rpms_dir that are also included in in old_rpms_dir

e.g
# ls old_rpms_dir
a.1.rpm b.1.rpm

# ls new_rpms_dir
a.2.rpm b.2.rpm z.0.rpm y.0.rpm

packages a and b are in both directories, so i want that a.2.rpm, b.2.rpm will be copied from new_rpms_dir to a directory "rpms_up2date_dir"

please help

Regards
5 REPLIES
Steven E. Protter
Exalted Contributor

Re: script that copies upgraded rpms ?

Shalom,

ls -1 /old/ | sort -u > list.old
ls -1 /new/ | sort -u > list.new

while read -r filenew
do
there=$(grep $filenew list.old |wc -l)
if [ $there = 1 ] then
cp $filenew
fi
done < list.new

Some debugging required. Your milage may vary.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Alexander Chuzhoy
Honored Contributor

Re: script that copies upgraded rpms ?

#!/bin/bash
for i in `ls new_rpms`;do
if [ ! -f old_rpms/${i} ]; then
cp new_rpms/${i} rpms_up2date ;
fi
done
Maaz
Valued Contributor

Re: script that copies upgraded rpms ?

Dear SEP, and Alexander thanks for prompt reply/help

I'll check the code on tommorow, and will back to the forum with the result.

as my knowledge of Linux and particularly of scripting is almost equal to ZERO, thats why i cant comment at the moment.

Hi Alexander,
> if [ ! -f old_rpms/${i} ]; then
> cp new_rpms/${i} rpms_up2date ;

Alexander, do you think the code will work as I want ? I mean the code will only copy those files(from new_rpms_dir) that are also included in old_rpms_dir ?
my guess says that the code will also copy those additional rpms that are not the part of old_rpms_dir.

if the new_rpm_dir contains gnome-applet-devel but this rpm is not included in old_rpm_dir then I dont want that rpm to be copied from new_rpm_dir to the rpm_up2date_dir

but if new-rpms_dir contains gnome-desktop-devel-3.7.23.67 and the old_rpms_dir contains gnome-desktop-devel-3.7.8.9, then I want this rpm to be copied from new_rpms_dir to the rpm_up2date_dir

Sorry for any inconvenience

Regards
Alexander Chuzhoy
Honored Contributor

Re: script that copies upgraded rpms ?

You're right.
I got confused and the code actually checks for the opposite. Simply remove the exclamation mark and it'll do what you want.
Maaz
Valued Contributor

Re: script that copies upgraded rpms ?

Thanks Alexander for help/reply


#!/bin/bash
for i in `ls new_rpms`;do
if [ ! -f old_rpms/${i} ]; then
cp new_rpms/${i} rpms_up2date ;
fi
done


will also copy additional(unwanted) files/rpms from new_rpms_dir.
----


#!/bin/bash
for i in `ls new_rpms`;do
if [ -f old_rpms/${i} ]; then
cp new_rpms/${i} rpms_up2date ;
fi
done


when I use the above code(without "!" in 'if' ) then script doesn't copy any single file(do nothing).

Please help
Regards