O Plameras wrote:

Philip Greggs wrote:

Hi,

Wish you could help.

My RPMs and SRC.RPMs are now over  10GB. Have
accummulated over the years.

Want to remove older versions, retaining only the latest.
Been doing this manually but can't cope any longer.

Any script that I can use ?

Try this.

#!/bin/sh
#
# Author     : O Plameras
# Date       : 18-Feb-2006
# Script : move older versions of rpm or src.rpm files to OBSOLETE/ dir.
#              You may remove OBSOLETE after manual examinations.
#
# Warning : Use this script at your own RISK. No Warranty, expressed or implied.
#
# Assumptions: RPM file has $1-$2-$3..$5 format.
#       Where:
#              $1     - software-name1
#              ...
#              $#-1   - version
#              $#     - release, org, type
#
PRV="NONE"
let C=0
[ -d OBSOLETE ] || mkdir OBSOLETE
for i in `ls *.rpm`
do
      set `echo $i | sed 's/-/ /g'`
      if [ $# == 3 ]; then
              if [ $1 == $PRV ]; then
                      mv $PF OBSOLETE/
                      let C=$C+1
              fi
              PRV=$1
      elif [ $# == 4 ]; then
              if [ $1-$2 == $PRV ]; then
                      mv $PF OBSOLETE/
                      let C=$C+1
              fi
              PRV=$1-$2
      elif [ $# == 5 ]; then
              if [ $1-$2-$3 == $PRV ]; then
                      mv $PF OBSOLETE/
                      let C=$C+1
              fi
              PRV=$1-$2-$3
      fi
      PF=$i
done
#
echo "There are $C files to remove."
exit 0

Hi Philip,

New version of the script. Simpler and better
in terms of self-documentation.

#!/bin/sh
#
# Author     : O Plameras
# Version    : 0.2
# Date         : 19-Feb-2006
# Script : move older versions of rpm or src.rpm files to OBSOLETE/ dir.
#               You may remove OBSOLETE after manual examinations.
#
# Warning : Use this script at your own RISK. No Warranty, expressed or implied.
#
function checkV(){
       if [ $CUR == $PRV ]; then
               mv $PF OBSOLETE/
               let C=$C+1
       fi
       PRV=$CUR
}
PRV="NONE"
let C=0
[ -d OBSOLETE ] || mkdir OBSOLETE
for i in `ls *.rpm`
do
       set `echo $i | sed 's/-/ /g'`
       case "$#" in
               3)
                       CUR=$1
                       checkV
                       ;;
               4)
                       CUR=$1-$2
                       checkV
                       ;;
               5)
                       CUR=$1-$2-$3
                       checkV
                       ;;
               *)
                       ;;
       esac
       PF=$i
done
#
echo "There are $C files to remove."
exit 0

O Plameras


--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to