HoganHost blog

[email protected]

How to delete millions thousands of exim mail queues using ssh command line

We will work you through on How to delete millions thousands of exim mail queues using ssh command line, What will you do when some of your scripts are infected and injected with mail sending script.

That sends millions of mails, curing the script is the first step and its easy too. but clearing the millions of mails on mail queue, that will be like pain in the a**

There are few simple ways to clear the mail queues.

To find the no of mails on the mail(exim) queue, use
exim -bpc
This command may take some time to display the result, which depends on the no of mails in the queue.

First one is to delete whole queue, if its only few thousand mails.
Using the exim -bo

exim -bp | grep "<"|awk {'print $3'}|xargs exim -Mrm

You also try the below commands, which is categorized.

#Remove the frozen messages.

exim -bpru|grep frozen|awk {'print $3'}|xargs exim -Mrm

#Remove nobody mails

exim -bpru|grep nobody|awk {'print $3'}|xargs exim -Mrm

#Remove mail older than 1 day

exiqgrep -o 86400 |awk {'print $3'}|xargs exim -Mrm

The above commands will clear the mails only when you keep the exim running.
that will be the hard task and exim may create new mails to delivery.

If the above commands didn’t work for you, then the alternate way is to delete the mails manually.

We have to do it in the hardway. ?

Just stop the mail server by

service exim stop

then, change directory to /var/spool/exim

cd /var/spool/exim

Now, execute the below command, which will delete all the mails on the mail queue folder.

find input -type f -exec rm -rf {} \;

Now, we also need to run the command for msglog folder too.

find msglog -type f -exec rm -rf {} \;

Once done, start the mailserver exim.

service exim restart

I hope this helped you, check out our web hosting plan

Leave a Comment

Your email address will not be published. Required fields are marked *