All pastes #1602946 Raw Edit

etrn-poke

public shellscript v1 · immutable
#1602946 ·published 2009-10-08 01:21 UTC
rendered paste body
#!/bin/bash### Script to poke a remote/backup MX server using ETRN#	Copyright (c) 2009 Phillip Smith# Version NumberVER=0.1.1# Path to options filecase $# in1)	BACKUP_MX="$1"	OPTIONS_FILE='/etc/etrn-poke/options.conf'	;;2)	BACKUP_MX="$1"	OPTIONS_FILE="$2"	;;*)	echo "Usage: $0 remote-mx-server [options file]"	exit 1	;;esac## Check config file existsif [ -e "$OPTIONS_FILE" ] ; then	source $OPTIONS_FILE	if [ -z "$EP_OPT_VER" -o "$EP_OPT_VER" != $VER ] ; then		echo "I DIED! Options file invalid or version mismatch"		exit 1	fielse	echo "I DIED! Failed to find the options file: $OPTIONS_FILE"	exit 1fi## Make all config variables from optons.conf READ-ONLYdeclare -r PSQLdeclare -r SEDdeclare -r TRdeclare -r FETCHMAILMISSING_BIN=''[ -x "$PSQL" ]		|| MISSING_BIN="$MISSING_BIN psql not found: $PSQL\n"[ -x "$SED" ]		|| MISSING_BIN="$MISSING_BIN sed not found: $SED\n"[ -x "$TR" ]		|| MISSING_BIN="$MISSING_BIN tr not found: $GREP\n"[ -x "$FETCHMAIL" ]	|| MISSING_BIN="$MISSING_BIN fetchmail not found: $FETCHMAIL\n"if [ -n "$MISSING_BIN" ] ; then	echo "Some required programs were not found. Please check $OPTIONS_FILE to ensure correct paths are set."	echo "The missing files are:"	echo -e $MISSING_BINfi## Find a list of domains we are primary forif [ "$USE_DB" = 'yes' ] ; then	export PGPASSWORD="$PGSQL_PASSWORD"	DOMAINS=`$PSQL --host=$PGSQL_HOST --username=$PGSQL_USERNAME --dbname=$PGSQL_DATABASE --no-password -P format=Unaligned -P fieldsep=, -tqc "SELECT \"$PGSQL_COL\" FROM \"$PGSQL_TABLE\" WHERE backupmx IS FALSE AND active IS TRUE ORDER BY 1;" | $SED -e 's/ALL//g'`	if [ $? -ne 0 ] ; then		echo "Failed to retrieve domain list from PostgreSQL server ($PGSQL_HOST) with username $PGSQL_USERNAME"		exit 1	else		ETRN_LIST=`echo $DOMAINS | $TR ' ' ','`	fifi## Poke the remote MX serverFETCHMAIL_OPTS='-v'if [ -n "$ETRN_LIST" ] ; then	$FETCHMAIL -q -p ETRN --fetchdomains $ETRN_LIST $FETCHMAIL_OPTS $BACKUP_MX	RETVAL=$?else	echo "No domains in the ETRN list; Aborting the poke!"	RETVAL=1fiexit $RETVAL