[Exim] exim admin script - eximadm

Top Page
Delete this message
Reply to this message
Author: Benedikt Hochstrasser
Date:  
To: exim-users
Subject: [Exim] exim admin script - eximadm
Hello,
for those who are interested I have a simple dialog-based admin tool that allows
to view the exim queue, thaw/freeze/delete and cancel waiting messages. The bash
script should be self-explanatory, so here it is:


#!/bin/bash
# eximadm is written by B. Hochstrasser (bhoc@???)
# this is GPL
#
# this is a simple dialog-based exim mail queue admin tool.
# if you don't know exim, go to http://www.exim.org
#

# some constants
# where is exim?
EXIMCMD="/usr/bin/exim"
# this matches frozen msgs
FROZEN="*** frozen ***"
# get a filename for the temp file
TMPFILE="/tmp/eximadm-$(date +%s)"
# filter out all but '-00 <'
MATCH="\-[0-9][0-9] <"
# sed script
SEDCMD="s/>.*$/> 0/"

# some functions
thaw ()
{
MSGLIST=$(${EXIMCMD} -bp | grep "${MATCH}" | grep "${FROZEN}" | cut -b 11- | sed -e "${SEDCMD}" | tr "\n" " ")
if [ -n "${MSGLIST}" ]; then
  dialog --title "Thaw Messages" --checklist "Message ID - Sender" 0 0 0 ${MSGLIST} 2>${TMPFILE}
  MSGLIST=$(cat ${TMPFILE} | tr -d '"')
  if [ -n "${MSGLIST}" ]; then
    EXIMSG=$(${EXIMCMD} -Mt ${MSGLIST})
    RM ${TMPFILE} 
    if [ -n "${EXIMSG}" ]; then
      dialog --title "Exim Messages" --msgbox "${EXIMSG}" 0 0
    fi
  fi
fi
}


freeze ()
{
MSGLIST=$(${EXIMCMD} -bp | grep "${MATCH}" | grep -v "${FROZEN}" | cut -b 11- | sed -e "${SEDCMD}" | tr "\n" " ")
if [ -n "${MSGLIST}" ]; then
  dialog --title "Freeze Messages" --checklist "Message ID - Sender" 0 0 0 ${MSGLIST} 2>${TMPFILE}
  MSGLIST=$(cat ${TMPFILE} | tr -d '"')
  if [ -n "${MSGLIST}" ]; then
    EXIMSG=$(${EXIMCMD} -Mf ${MSGLIST})
    RM ${TMPFILE} 
    if [ -n "${EXIMSG}" ]; then
      dialog --title "Exim Messages" --msgbox "${EXIMSG}" 0 0
    fi
  fi
fi
}


editall ()
{
MSGTITLE=$1
EXIMOPT=$2
if [ -n "${EXIMOPT}" ]; then
  MSGLIST=$(${EXIMCMD} -bp | grep "${MATCH}" | cut -b 11- | sed -e "${SEDCMD}" | tr "\n" " ")
  if [ -n "${MSGLIST}" ]; then
    dialog --title "${MSGTITLE} Messages" --checklist "Message ID - Sender" 0 0 0 ${MSGLIST} 2>${TMPFILE}
    MSGLIST=$(cat ${TMPFILE} | tr -d '"')
    if [ -n "${MSGLIST}" ]; then
      EXIMSG=$(${EXIMCMD} ${EXIMOPT} ${MSGLIST})
      RM ${TMPFILE} 
      if [ -n "${EXIMSG}" ]; then
        dialog --title "Exim Messages" --msgbox "${EXIMSG}" 0 0
      fi
    fi
  fi
fi
}


viewqueue ()
{
MSGLIST=$(${EXIMCMD} -bp)
if [ -n "${MSGLIST}" ]; then
dialog --title "Exim Mail Queue" --msgbox "${MSGLIST}" 0 0
fi
}

# the main loop
CMD="XXX"
until [ -z "${CMD}" ]; do
  if [ -z "$(${EXIMCMD} -bp)" ]; then
    dialog --title "Nothing To Do" --msgbox "The Message Queue is empty." 0 0
    CMD=""
  else
    dialog --title "Select Exim Task" --menu "What do you want to do\nwith not-yet-sent Messages?" 0 0 0 \
      view "View the Mail Queue" \
      retry "Retry Sending Messages" \
      delete "Delete Messages" \
      thaw "Thaw frozen Messages" \
      freeze "Freeze Messages" \
      cancel "Cancel Messages" \
      2>${TMPFILE}
    CMD=$(cat ${TMPFILE})
    case "${CMD}" in
      view) viewqueue;;
      thaw) thaw;;
      freeze) freeze;;
      delete) editall Remove -Mrm;;
      cancel) editall Cancel -Mg;;
      retry) editall Retry -M;;
    esac
    rm ${TMPFILE}
  fi
done; 
# End of Script


Have fun! Ben