Skip to content

Instantly share code, notes, and snippets.

@grepwood
Created August 20, 2014 11:31
Show Gist options
  • Save grepwood/6acbcddbc143aca0f914 to your computer and use it in GitHub Desktop.
Save grepwood/6acbcddbc143aca0f914 to your computer and use it in GitHub Desktop.
Resets qmail queue, appropriately archives the old one and leaves behind a useful symlink to the latest bad queue
#!/bin/bash
USER=`whoami`
if [ "$USER" != "root" ]; then
echo "Must be run as root or sudo."
else
cd /var/qmail
service smtp stop
# service send stop
ENTIRE_DATE=`date -R`
YEAR=`echo $ENTIRE_DATE | awk '{print $4}'`
MONTH=`echo $ENTIRE_DATE | awk '{print $3}'`
DAY=`echo $ENTIRE_DATE | awk '{print $2}'`
HMS=`echo $ENTIRE_DATE | awk '{print $5}'`
echo "Creating directory for bad queue..."
mkdir -p bad/$YEAR/$MONTH/$DAY
mv queue bad/$YEAR/$MONTH/$DAY/$HMS
echo "Resetting symlink to latest bad queue..."
rm -f latest.bad
ln -s bad/$YEAR/$MONTH/$DAY/$HMS latest.bad
echo "Setting up new queue..."
yum -y -q reinstall qmail
echo "Restarting smtp and send..."
service smtp start
# service send start
echo "All done!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment