Tag: Bash
Default Mail Clean Script
by Eric on Mar.17, 2009, under Linux, Scripts
Here's a quick little script to clean the default mail accounts of mail on cPanel servers. Note that this only helps if you have already disabled the catchalls.
#!/bin/bash
###############################################
# CLEAN MAIL #
# v0.1 #
# #
# Cleans the mail from default accounts based #
# on cPanel usernames. Create a file in /root #
# called 'doit'. Add one cPanel username per #
# line. That should do nicely. Oh, this will #
# take a while, so run the sucker in screen, #
# mkay, Batman? #
###############################################
# Some dedis have LS_OPTIONS include -a...
# that would be bad for this script.
# so, we reset it.
LS_OPTIONS='-A'
# start the loop...
for i in `cat /root/doit`
do
# Delete from the new folder.
cd /home/$i/mail/new
# can't rm if there's too many, and by using
# an ls and awk, we avoid another loop.
ls -l | awk '{print "rm -fv "$9}'|bash
# Delete from the cur folder.
cd /home/$i/mail/cur
# Comment repetition carefully avoided, here ![]()
ls -l | awk '{print "rm -fv "$9}'|bash
done
# NINJAMOJO!
It's simple. Get a list of cPanel usernames, one per line, create a file in /root called 'doit', and slap the usernames in there. Then, 'bash cleanmail'.





