How could I go about mass emptying all emails on the server, for all accounts? So that at the end, every single mailbox on the server is empty.
#!/bin/tcsh -f
foreach user ( `ls /home` )
echo
echo Processing $user.......
find /home/$user/mail -type f -fprint usr
echo
echo "The following files will be emptied in 10 seconds! Press Ctrl-C to stop!"
cat usr
sleep 10
foreach file ( `cat usr` )
echo "" | sed '{/^$/D}' > $file
echo
echo ..done
end
echo echo ...All done
end
Yes, everything would still work.TheStarKillers said:But it will leave the emails working to receive further emails? Like if someone sends an email after I run it, will it get bounced or will the files be re-created (although without the previous emails)? Thanks!
#! /bin/bash
# this is horribly dangerous so just make sure
echo "EMail removal program\n\n"
who="ON THIS WHOLE SERVER"
[ $# != 0 ] && who="for $*"
echo "ALL EMAIL $who WILL BE REMOVED IF YOU CONTINUE"
echo -n "DO YOU REALLY WANT TO ERASE ALL EMAIL $who ('YES' to proceed) [NO]? "
read answer
case "$answer" in
YES) ;;
*) echo "You must answer 'YES' to continue, aborting"
exit 1
;;
esac
if [ $# != 0 ]
then
USERS="$*"
else
USERS=$(ls /home)
fi
cd /home
for user in $USERS
do
[ ! -d $user/mail ] && continue
echo Processing $user ...
if [ -d $user/mail/new ]
then
# the maildir version
find $user/mail -type f -print | xargs -t rm -f
else
# the mbox version
find $user/mail -type f -print | while read file
do
cat < /dev/null > $file
done
fi
done
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
I | Exim replace empty Subject | 1 | ||
J | Greylisting enabled but reports empty - looks like doesn't work | 3 | ||
R | In Progress Empty Junk box | 3 | ||
S | eximstats mysql table remains empty - users cannot "Trace Emails" in cpanel | 5 | ||
T | boxtrapper - empty queue emails | 1 |