Build a function for RPM cleanup

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Sometimes the rpmdb checksum is invalid. To fix that I have created a simple function in bash script that reads the input from stdin. If yes in any kind or y ignore case is entered, the rpmdb will be rebuild and we clean the local yum cache.

See also Red Hat Enterprise Linux - Working with yum cache.

read -r -p "Are you sure? [y/N] " response if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]] then
  if [ -f /var/lib/rpm/.rpm.lock ]
      echo ".. RPM operation in progress. Try later. Abort cleanup."
      echo ".. rebuild RPM database"
      rpm --rebuilddb
      echo ".. clean local yum rpmdb cache"
      yum clean rpmdb
Please remember the terms for blog comments.