The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cron Job to Delete Mail Queue

Discussion in 'E-mail Discussions' started by salvatore333, Jul 7, 2005.

  1. salvatore333

    salvatore333 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  2. iquest

    iquest Active Member

    Joined:
    Mar 16, 2004
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    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....
     
  3. bijo

    bijo Well-Known Member

    Joined:
    Aug 21, 2004
    Messages:
    475
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India

    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.
     
  4. bijo

    bijo Well-Known Member

    Joined:
    Aug 21, 2004
    Messages:
    475
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India


    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.
     
  5. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    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.
     
  6. salvatore333

    salvatore333 Well-Known Member

    Joined:
    Mar 27, 2003
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16

    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.
     
  7. iquest

    iquest Active Member

    Joined:
    Mar 16, 2004
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    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)
     
  8. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
  9. iquest

    iquest Active Member

    Joined:
    Mar 16, 2004
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  10. iquest

    iquest Active Member

    Joined:
    Mar 16, 2004
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    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 :)...
     
  11. bijo

    bijo Well-Known Member

    Joined:
    Aug 21, 2004
    Messages:
    475
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India
    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 :)
     
    #11 bijo, Jul 7, 2005
    Last edited: Jul 7, 2005
  12. iquest

    iquest Active Member

    Joined:
    Mar 16, 2004
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    You are most welcome...
     
  13. bmcpanel

    bmcpanel Well-Known Member

    Joined:
    Jun 1, 2002
    Messages:
    546
    Likes Received:
    0
    Trophy Points:
    16
    FYI, that does not work.
     
  14. iquest

    iquest Active Member

    Joined:
    Mar 16, 2004
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
  15. Hip Hop Servers

    Joined:
    Feb 16, 2005
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
    #15 Hip Hop Servers, Jan 10, 2008
    Last edited: Jan 10, 2008
Loading...

Share This Page