Linux Training

Linux training for private, public & voluntary sector.

0793 572 8612

City LinUX sample scripts - rmq


#!/bin/bash
# $Id: rmq,v 1.25 2015/04/03 08:39:24 fulford Exp $
# $Source: /src/merlin/usr/local/etc/RCS/rmq,v $
# $Revision: 1.25 $
# Author C W Fulford.
# Copyright 2014 (c) C W Fulford.
# Licensed for public use under the LGPL, .
# For assistance contact fulford@fulford.net 0709 229 5385
########################################################################
cmd=`basename $0`
syntax="$cmd [-d ] [-l] [-v] <client_id|hostname>"
while [ $# -gt 0 ] ;do
	case $1 in 
		-d) debug=:;set -x;shift;;
		-l) log=:;shift;;
		-v) verbose=:;shift;;
		-V) echo "$cmd $Revision: 1.25 $"|awk '{print $1,$3}';exit;;  
		 *) clientid=$1;shift
	esac
done
[ `id -u` -lt 500 ]&&{ echo "$cmd: do not use with privileged ids">&2;exit 1;}
tmp=/var/tmp/$cmd.$$
[ -z "$clientid" ]&&{
	echo -e "$cmd: No hostname or clientid!\nsyntax: $syntax" >&2
	exit 1
}  
config=${config:-"/usr/local/etc/rmq.cf"}
[ -f $config ] || { echo "$cmd: $config not found!" >&2 ;}

if grep -Eq "^${clientid}:" $config ;then
       sed -ne "/^${clientid}:$/,/^$/{
       			/^[ 	].*=.*/p
		}" $config> $tmp
       . $tmp
else
	echo "$cmd: $clientid not in $config!" >&2
fi
host=${host:=$clientid}
[ "$verbose" ] && echo "$cmd: target host= $host"
nslookup $host >/dev/null ||{ echo "$cmd: $host has no ip!";exit 1;}
case $mta in
	postfix) rqcmd="/usr/sbin/postqueue -p";;
	sendmail) rqcmd="sudo /usr/sbin/sendmail -bp";;
	*) echo "$cmd: don't know how to process $mta queue">&2;exit 1;;
esac
if [ $verbose ];then
	rqueue=`ssh $host "$rqcmd"`
else
	rqueue=`ssh $host "$rqcmd" |awk '/^--/{gsub(/--/,"");print}'`
fi
rqueue=${rqueue:-"queue empty"}
[ "$verbose" ] && echo "$cmd: $host $rqueue"
if [ $log ] ;then
       	logger -t rmq "$host $rqueue"
else
	echo "$cmd: $rqueue on $host"
fi

######################################################################
# This program is free software: you can redistribute it and or      #
# modify it under the terms of the Lesser GNU General Public License #
# as published by the Free Software Foundation, either version 3 of  #
# the License, or (at your option) any later version.                #
#                                                                    #
# 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.  See the      #
# GNU General Public License for more details.                       #
#                                                                    # 
# A copy of the Lesser GNU General Public License and the GNU        #
# General Public License is available at                             #
# <http://www.gnu.org/licenses/>.                                    #
######################################################################
######################################################################
# This program is free software: you can redistribute it and or      #
# modify it under the terms of the Lesser GNU General Public License #
# as published by the Free Software Foundation, either version 3 of  #
# the License, or (at your option) any later version.                #
#                                                                    #
# 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.  See the      #
# GNU General Public License for more details.                       #
#                                                                    # 
# A copy of the Lesser GNU General Public License and the GNU        #
# General Public License is available at                             #
# <http://www.gnu.org/licenses/>.                                    #
######################################################################

The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.