Skip to content

Instantly share code, notes, and snippets.

@weavenet
Created January 11, 2012 15:42
Show Gist options
  • Save weavenet/1595238 to your computer and use it in GitHub Desktop.
Save weavenet/1595238 to your computer and use it in GitHub Desktop.
Script To Remove Non Whitelists RPMs
#!/bin/bash
whitelist=ami_rpm_whitelist.txt
# List rpms to installed rpmts
rpm -q -a > /tmp/installed_rpms
# create white list file of rpms installed on the given whitelist
for i in `cat $whitelist |tr -d '\r'`; do
egrep ^$i /tmp/installed_rpms
done |uniq > /tmp/whitelist_installed_rpms
# If a given install rpm is not in the whitelisted rpms, remove it
for i in `cat /tmp/installed_rpms | tr '++' '..'`; do
egrep $i /tmp/whitelist_installed_rpms > /dev/null
if [ $? -ne 0 ]; then
yum -y erase $i
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment