Linux Training

Linux training for private, public & voluntary sector.

0793 572 8612

City LinUX sample scripts - rmmr


#!/bin/bash
# $Id: rmmr,v 1.13 2015/07/07 17:23:52 fulford Exp $
# $Source: /src/merlin/usr/local/etc/RCS/rmmr,v $
# $Revision: 1.13 $
# Author C W Fulford.
# Copyright 2015 (c) C W Fulford.
# Licensed for public use under the LGPL, .
# For assistance contact fulford@fulford.net 0709 229 5385
########################################################################
cmd=`basename $0`
ver=`echo "$Id: rmmr,v 1.13 2015/07/07 17:23:52 fulford Exp $"|awk '{print $3,$4,$5}'`
syntax="$cmd [-c <configfile>] [-d] <name> [-v]|-V"
while [ $# -gt 0 ] ;do
	case $1 in 
		-c) config=$2;shift 2;;
		-d) set -x;debug=0;shift;;
		-v) verbose=:;shift;;
		-V) echo "$cmd $Revision: 1.13 $ $Date: 2015/07/07 17:23:52 $"|awk '{print $1,$3,$6}';exit;;  
		 *) name=$1;shift;;
	esac
done

[ -z "$name" ] &&{ echo "syntax: $syntax" >&2;exit 1;}

config=${config:-/usr/local/etc/mailout.cf}

[ -r $config ]||{ echo "$cmd: Can\'t find $config" ;exit 1 ;}

eval  `sed -ne '/^[ 	]*[^#]/p' $config`
srcdir=/src/`hostname`
[ -d $srcdir ] ||{
	echo "$cmd: Can\'t find \"$srcdir\"." >&2
	exit 1
}
data=${data:-/var/mailout/data.csv}
data=$srcdir$data
deleted=${deleted:-/var/mailout/deleted.csv}
deleted=$srcdir$deleted
matches=`grep -c $name $data` 
[ $matches -ne 1 ] && { 
	[ $matches -eq 0 ] &&{
		echo "$cmd: no match for \"$name\" found in \"$data\"" >&2
	}
	[ $matches -gt 1 ] &&{
		echo "$cmd: \"$name\" matches more than 1 record in \"$data\"." >&2
	}
	exit 1
}
[ -w $deleted ] ||{
	echo "$cmd: Can\'t write to \"$deleted\"." >&2
	exit 1
}
[ -w $data ] ||{
	echo "$cmd: Can\'t write to \"$data\"." >&2
	exit 1
}
if ! grep $name $data >>$deleted ;then
	echo "$cmd: Can\'t update \"$deleted\"." >&2
	exit 1
else
	[ $verbose ] && echo "$cmd: \"$deleted\" updated."
	ed -s $data <<- . 
		/$name/d
		wq
		.
	[ $? -eq 0 ] && echo "cmd: \"$data\" updated."
fi
cd `dirname $data` 
pdata=`basename $data`
pdeleted=`basename $deleted`
if make -s $pdata  < /dev/null ;then
	[ $verbose ] && echo "$cmd: production file \"$pdata\" updated."
fi
if make -s $pdeleted  < /dev/null ;then
	[ $verbose ] && echo "$cmd: production file \"$pdata\" updated."
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/>.                                    #
######################################################################

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.