Wednesday, April 13, 2011

How to clear sendmail queue

SkyHi @ Wednesday, April 13, 2011
If you ever felt the need of flushing the sendmail queue then this post will be handy to you.

How to flush sendmail queue under linux sendmail mailq command in linux how to flush mail queue in sendmail under linux

If u r worried about sendmail pending mail flush do the following 2 things.

1) manually method –> delete /var/spool/mail/*.* files in this dir –> delete /var/mqueue/*.* files

then check if all mail gone using mailq command. all mail will be deleted.

2) using command:

use simple command sendmail -v -q in root prompt. it will flush all pending mails. rest to confirm u can run mailq command if all are really gone !!….

3) if u want perticular domain or user or recepitience mail to delete use this command

sendmail -qS -v test.com it will delete all mail from *@test.com

sendmail -qR -v hotmail.com it will delete all mail from recepient of hotmail….


REFERENCES
http://www.kpsolution.com/blog/tips/how-to-clear-sendmail-queue/9/

Tuesday, April 12, 2011

Force yum update Command To Exclude Certain Packages

SkyHi @ Tuesday, April 12, 2011
Q. How can I exclude selected packages when I rum yum update command under CentOS Linux server?

A. Yum uses a configuration file at /etc/yum/yum.conf or /etc/yum.conf. You need to place exclude directive to define list of packages to exclude from updates or installs. This should be a space separated list. Shell globs using wildcards * and ?) are allowed.
How do I exclude php and kernel packages when I use "yum update"?

Open /etc/yum.conf file:
# vi /etc/yum.conf
Append following line under [main] section, enter:
exclude=php* kernel*
At the end, it should look like as follows:

[main]
cachedir=/var/cache/yum
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
exclude=php* kernel*

# Note: yum-RHN-plugin doesn't honor this.
metadata_expire=1h

# Default.
# installonly_limit = 3

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

yum --exclude command line option

Finally, you can skip yum command updates on command line itself using following syntax:
# yum --exclude=package* update
# yum --exclude=php* update
# yum --exclude=kernel* update


REFERENCES
http://www.cyberciti.biz/faq/redhat-centos-linux-yum-update-exclude-packages/

Getting yum updates by E-mail

SkyHi @ Tuesday, April 12, 2011
I run several CentOS 4.0 servers, and having to manually check each server for new updates is tedious. To simplify my life, I decided to write a shell script (yumnotifier) to E-mail me when new updates are available. The script (yumnotifier) analyzes the output from ‘yum check-update,’ and generates an E-mail similar to the following if updates are available:

From root@localhost.localdomain Sat Jul 15 19:24:59 2006
Date: Sat, 15 Jul 2006 19:24:59 -0400
From: root
To: matty@localhost.localdomain
Subject: Updates available for biscuit

==== The following updates are available for biscuit ===

comps.i386 2:4.3CENTOS-0.20060314 base
gtk2.i386 2.4.13-18 base
kernel.i686 2.6.9-34.0.2.EL update
libtiff.i386 3.6.1-10 update
mysql.i386 4.1.20-1.RHEL4.1 update
mysql-devel.i386 4.1.20-1.RHEL4.1 update

If you manage systems that use yum, you might be interested in this script.

#!/bin/sh 
#
# Program: E-mail available yum updates <yumnotifier>
#
# Author: Matty < matty91 at gmail dot com >
#
# Current Version: 1.2
#
# Revision History:
#
#  Version 1.2
#    - Removed ! from if statement - John Beaman
#    - Changed comments to reference "yumnotifier", not
#      "yumupdate" -- John Beaman
#
#  Version 1.1
#    - Switched test statement to use "-s" - Luca Rozza
#
#  Version 1.0
#    Initial Release
#
# Last Updated: 10-24-2007
#
# Purpose:
#   yumnotifier checks for updated software package, and E-mails the
#   address defined in the ${ADMIN} variable if updates are available.
#
# License:
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Installation:
#   Copy the shell script to a suitable location
#
# Usage:
#   To check for new updates each day at midnight, a cron job similar to the
#   following can be used:
#
#   $ crontab -l | grep yumnotifier
#   0 0 * * * /etc/scripts/yumnotifier
#
# Sample output
#   An E-mail similar to the following is sent if updates are available:
#
#   From root@localhost.localdomain  Sat Jul 15 19:24:59 2006
#   Date: Sat, 15 Jul 2006 19:24:59 -0400
#   From: root <root@localhost.localdomain>
#   To: matty@localhost.localdomain
#   Subject: Updates available for biscuit
#  
#   ==== The following updates are available for biscuit ===
#  
#   comps.i386                               2:4.3CENTOS-0.20060314 base            
#   gtk2.i386                                2.4.13-18              base            
#   kernel.i686                              2.6.9-34.0.2.EL        update          
#   libtiff.i386                             3.6.1-10               update          
#   mysql.i386                               4.1.20-1.RHEL4.1       update          
#   mysql-devel.i386                         4.1.20-1.RHEL4.1       update          
#   newt.i386                                0.51.6-7.rhel4         base            
#   php.i386                                 4.3.9-3.15             update          
#   php-ldap.i386                            4.3.9-3.15             update          
#   php-pear.i386                            4.3.9-3.15             update          
#   postgresql-libs.i386                     7.4.13-2.RHEL4.1       update          
#   rpmdb-CentOS.i386                        2:4.3-0.20060314       base            
#   sendmail.i386                            8.13.1-3.RHEL4.5       update          
#   sendmail-cf.i386                         8.13.1-3.RHEL4.5       update          
#   spamassassin.i386                        3.0.6-1.el4            update          
#   vixie-cron.i386                          4:4.1-44.EL4           update          
#   xorg-x11-Mesa-libGL.i386                 6.8.2-1.EL.13.25.1     update          
#   xorg-x11-font-utils.i386                 6.8.2-1.EL.13.25.1     update          
#   xorg-x11-libs.i386                       6.8.2-1.EL.13.25.1     update          
#   xorg-x11-xauth.i386                      6.8.2-1.EL.13.25.1     update          
#   xorg-x11-xfs.i386                        6.8.2-1.EL.13.25.1     update        

PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH

# Locations of binaries
GREP="/bin/grep"
HOST=`hostname`
MAIL="/bin/mail"
MKTEMP="/bin/mktemp"
YUM="/usr/bin/yum"

# Who to E-mail with new updates
ADMIN="matty"

if [ ! -f ${YUM} ]
then
        echo "Cannot find ${YUM}"
        exit 1
fi

if [ ! -f ${MKTEMP} ]
then
        echo "Cannot find ${MKTEMP}"
        exit 1
fi

if [ ! -f ${MAIL} ]
then
        echo "Cannot find ${MAIL}"
        exit 1
fi

if [ ! -f ${GREP} ]
then
        echo "Cannot find ${GREP}"
        exit 1
fi

# Dump the yum results to a safe working file
WORK=`${MKTEMP} /tmp/yum.results.XXXXXX`

${YUM} -e0 -d0 check-update > ${WORK}

# If there are updates available, E-mail them
if [ -s ${WORK} ]
then
        REPORT=`${MKTEMP} /tmp/yum.report.XXXXXX`
        echo "==== The following updates are available for ${HOST} ===" > ${REPORT}
        cat ${WORK} >> ${REPORT}
        cat ${REPORT} | ${MAIL} -s "Updates available for ${HOST}" ${ADMIN}
fi

# Cleanup temporary files
rm ${REPORT} ${WORK}



Great script – much better than my last attempt to do this. I made a small change to ignore kernel updates and only send an email if the return code for yum check-update is not zero:

${YUM} -e0 -d0 check-update –exclude=kernel* > ${WORK}

# If there are updates available, E-mail them
if [ $? -ne "0" ]
then
REPORT=`${MKTEMP} /tmp/yum.report.XXXXXX`
echo “==== The following updates are available for ${HOST} ===” > ${REPORT}
cat ${WORK} >> ${REPORT}
cat ${REPORT} | ${MAIL} -s “Updates available for ${HOST}” ${ADMIN}

REFERENCES
http://prefetch.net/blog/index.php/2006/07/16/getting-yum-updates-by-e-mail/
http://prefetch.net/code/yumnotifier