Cron Job to Delete Mail Queue

salvatore333

Well-Known Member
Mar 27, 2003
229
0
166
Can someone please give me the ssh comands to setup a cron job to delete my mail queue every couple of hours?

Thank you very much
 

iquest

Active Member
Mar 16, 2004
29
0
151
salvatore333 said:
Can someone please give me the ssh comands to setup a cron job to delete my mail queue every couple of hours?

Thank you very much
Type this with root access:

Code:
crontab -e
then add the following lines

Code:
0 */2 * * * /scripts2/killeximq >/dev/null 2>&1
This will clear your mail queues in every two hours....
 

bijo

Well-Known Member
Aug 21, 2004
474
0
166
India
salvatore333 said:
Can someone please give me the ssh comands to setup a cron job to delete my mail queue every couple of hours?

Thank you very much

Hello,

create a file in /root
#cd /root
#cat rmail.sh

#!/bin/bash
/cd /var/spool/exim/input;
rm -rf *;

#sh rmail.sh

Then add this entry in your cron tab
#crontab -e
0 0-23/2 * * * /root/rmail.sh >/dev/null 2>&1
Then save the file.

it will help you to solve your issue ;)

Let me know the status.
 

bijo

Well-Known Member
Aug 21, 2004
474
0
166
India
iquest said:
Type this with root access:

Code:
crontab -e
then add the following lines

Code:
0 */2 * * * /scripts2/killeximq >/dev/null 2>&1
This will clear your mail queues in every two hours....


No, It don't work. There is no folder /scripts2 and also killeximq command in cpanel ;) And also the time setting is wrong. You have set the cron to work every 30 minute.
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
33
473
Go on, have a guess
Bear in mind that this is an extremely bad idea. If you do this you will definitely lose legitimate email. If you want to play with the mail queue you should do it through the mechansims provided with exim. If you're finding that your mail queue is getting out of hand (more than a few hundred emails) then you should fix the root cause of the problem and not ignore it by trying to remove what is an essential part of any MTA.
 

salvatore333

Well-Known Member
Mar 27, 2003
229
0
166
chirpy said:
Bear in mind that this is an extremely bad idea. If you do this you will definitely lose legitimate email. If you want to play with the mail queue you should do it through the mechansims provided with exim. If you're finding that your mail queue is getting out of hand (more than a few hundred emails) then you should fix the root cause of the problem and not ignore it by trying to remove what is an essential part of any MTA.

How do you suggest I go about fixing the root cause of the problem exactly?. I get over 1000 emails every 12 hours and eventually the server crashes if I dont clear it out. My provider states spamd is using alot of system resources.

Thank you very much for everyones help.
 

iquest

Active Member
Mar 16, 2004
29
0
151
salvatore333 said:
How do you suggest I go about fixing the root cause of the problem exactly?. I get over 1000 emails every 12 hours and eventually the server crashes if I dont clear it out. My provider states spamd is using alot of system resources.

Thank you very much for everyones help.
Sorry, for the wrong command for killing exim mail queues manually. The right command is as follows:

Code:
/usr/local/cpanel/whostmgr/bin/whostmgr2 killeximq
You can just add it with your cron as mentioned before. However, I agree 100% with chripy. It's really not a good idea since you'll be losing some legitimate emails for sure. You might consider doing it through WHM (Main >> Email >> Manage Mail Queue >> Delete all messages in Queue) - at least you'll have some idea about the queued messages you'll be deleting. I was wondering, why don't you configure RBL as it eliminates at least 80%~90% of the spams. You can also try chirpy's solution:

(http://www.configserver.com/cp/mailscanner.html)
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
33
473
Go on, have a guess

iquest

Active Member
Mar 16, 2004
29
0
151
bijo said:
No, It don't work. There is no folder /scripts2 and also killeximq command in cpanel And also the time setting is wrong. You have set the cron to work every 30 minute.
I saw the link '/scripts2/killeximq' from WHM and thought that it would work from command line as well. I should have checked it before posting it though. Anyway, the cpanel script for cleaning mail queues from command line is:

/usr/local/cpanel/whostmgr/bin/whostmgr2 killeximq

There are built-in exim commands for doing this as well. You can check the Unix manual for crontab. */2 means every two hours and (30 * * * *) would run the cron in every half an hour.

http://www.rt.com/man/crontab.5.html
 

iquest

Active Member
Mar 16, 2004
29
0
151
I found some interesting links for mailing the queued mails to another email address:

http://freebsd.munk.nu/archives/151-Forwarding-Mail-To-Gmail.html

You can also configure exim.conf in the router section:

Code:
clear_queue:
    driver = accept
    domains = Your.Client
    condition = Check for the $message_age here if needed
    transport = some_transport_to_save_it_away
or

Code:
clear_queue:
    driver = redirect
    domains = your.client
    condition = Check for the $message_age here if needed
    data = :blackhole:
You can get a detailed summary of spams with the following command from root:

Code:
exim -bp | exiqsumm
Or you can type the following command and exim will try to deliver the mails in queue including the frozen mails.

Code:
exim -qff
If you go through the exim documentation then you will see that if the message is frozen then you can delete them in one line command:

Code:
exim -bpru|grep frozen|awk {'print $3'}|xargs exim -Mrm
if the message is <> then run the following command:

Code:
exim -bpru|grep '<>'|awk {'print $3'}|xargs exim -Mrm
if you need to delete all messages from the queue:

Code:
exim -bpru|awk {'print $3'}|xargs exim -Mrm
Check the following link for some useful exim commands

http://www.togaware.com/linux/survivor/Exim.shtml

Or, you can simply ask a professional like chirpy to have your exim configured. His charges are very resonable. Search the forum and you'll see that sometimes he does it for free :)...
 

bijo

Well-Known Member
Aug 21, 2004
474
0
166
India
iquest said:
I found some interesting links for mailing the queued mails to another email address:

http://freebsd.munk.nu/archives/151-Forwarding-Mail-To-Gmail.html

You can also configure exim.conf in the router section:

Code:
clear_queue:
    driver = accept
    domains = Your.Client
    condition = Check for the $message_age here if needed
    transport = some_transport_to_save_it_away
or

Code:
clear_queue:
    driver = redirect
    domains = your.client
    condition = Check for the $message_age here if needed
    data = :blackhole:
You can get a detailed summary of spams with the following command from root:

Code:
exim -bp | exiqsumm
Or you can type the following command and exim will try to deliver the mails in queue including the frozen mails.

Code:
exim -qff
If you go through the exim documentation then you will see that if the message is frozen then you can delete them in one line command:

Code:
exim -bpru|grep frozen|awk {'print $3'}|xargs exim -Mrm
if the message is <> then run the following command:

Code:
exim -bpru|grep '<>'|awk {'print $3'}|xargs exim -Mrm
if you need to delete all messages from the queue:

Code:
exim -bpru|awk {'print $3'}|xargs exim -Mrm
Check the following link for some useful exim commands

http://www.togaware.com/linux/survivor/Exim.shtml

Or, you can simply ask a professional like chirpy to have your exim configured. His charges are very resonable. Search the forum and you'll see that sometimes he does it for free :)...
Well iquest :p Finally you did a great reply and i get a new information from you, One is the command and second one is the cron related (*/2). This post is really good and It is really appreciated :)
 
Last edited:

iquest

Active Member
Mar 16, 2004
29
0
151
bijo said:
Well iquest :p Finally you did a great reply and i get a new information from you, One is the command and second one is the cron related (*/2). This post is really good and It is really appreciated :)
You are most welcome...
 

bmcpanel

Well-Known Member
Jun 1, 2002
544
0
316
iquest said:
Type this with root access:

Code:
crontab -e
then add the following lines

Code:
0 */2 * * * /scripts2/killeximq >/dev/null 2>&1
This will clear your mail queues in every two hours....
FYI, that does not work.
 
Feb 16, 2005
14
0
151
I was able to use the following exim command to delete all the messages in que older then thirty (30) days.
Code:
exiqgrep -zi -o 2592000 | xargs exim -Mrm
I clear all the old and/or frozen mail from my mail que.
 
Last edited: