This post is older than a year. Consider some information might not be accurate anymore.
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 ]
then
echo ".. RPM operation in progress. Try later. Abort cleanup."
else
echo ".. rebuild RPM database"
rpm --rebuilddb
echo ".. clean local yum rpmdb cache"
yum clean rpmdb
fi
fi
;;