#!/bin/bash

staff_email='alert@aroncp.ihnetworks.com'

sshvar=`grep exclude  /etc/yum.conf | grep -o openssh | uniq`
if [ "$sshvar" = "openssh" ]; then
	exit
fi

cp /etc/yum.conf /etc/yum.conf.`date +%h-%d-%y-%s`

awk -F= '$1 == "exclude"{printf "#";}1' /etc/yum.conf > /tmp/yum.conf.aug27
cat /tmp/yum.conf.aug27 > /etc/yum.conf
rm -f /tmp/yum.conf.aug27

sed -i '/\[main\]/a \exclude= openssh* apache* bind-chroot courier* dovecot* exim* filesystem httpd* mod_ssl* mydns* mysql* nsd* perl* php* proftpd* pure-ftpd* ruby* spamassassin* squirrelmail*' /etc/yum.conf


yumist=`yum list | grep ypbind | grep -o ypbind`
if [ "$yumist" = "ypbind" ]; then
	echo "SUCCESS `hostname` openssh excluded in yum.conf and yum working fine" | mail -s "SUCCESS `hostname` openssh excluded in yum.conf and yum working fine" $staff_email
else
	echo "CRITICAL `hostname` openssh exclusion did not work" | mail -s "CRITICAL `hostname` openssh exclusion did not work" $staff_email
fi 

