Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Can't pipe exim queue length to email when run via cron

Discussion in 'E-mail Discussion' started by DigitalEssence, May 23, 2016.

  1. DigitalEssence

    DigitalEssence Active Member

    Joined:
    May 21, 2014
    Messages:
    28
    Likes Received:
    2
    Trophy Points:
    3
    cPanel Access Level:
    Root Administrator
    Hi,

    looking for some advice please.

    I'd like to set up a cron job to monitor the length of the exim queue and email me if it gets over X number of emails.

    At present I'm just running a simple test to email me the queue length. I've followed the instructions in this post: Exim queue size - auto-mail to myself but I can't get the queue length to show in the email when run as a cron.

    I have a file: /home/username/crons/mailqueue.sh

    which contains:

    #!/bin/sh
    /usr/sbin/exim -bpc | mail -s 'Exim queue size' info@myemailaddress


    This works if I run it from the command line with ./mailqueue.sh and I receive an email with the current number of emails in the queue.

    When I try and run it from a cron using:

    sh /home/digital1/crons/mailqueue.sh

    I get a blank email.

    /var/log/cron isn't helping as I just see the cron run.

    The thread above suggests a pathing issue and to use the full path to exim which I have but still no luck. I'm hoping it's something really simple I'm, missing.

    Thanks for your help.

    Hedley
     
    #1 DigitalEssence, May 23, 2016
    Last edited: May 23, 2016
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,803
    Likes Received:
    1,897
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. twhiting9275

    twhiting9275 Well-Known Member

    Joined:
    Sep 26, 2002
    Messages:
    556
    Likes Received:
    16
    Trophy Points:
    168
    cPanel Access Level:
    Root Administrator
    Twitter:
    While not a pipe, this will do the same thing, and won't spam the hell out of you. Configure it to notify you only if your mail queue is higher than a magic number!

    Code:
    #!/bin/bash
    DATE=`date +%F`
    #DATE=date`%Y-%m-%d`
    SUBJ="$HOSTNAME email queue report"
    #your email address
    MYEMAIL="youremailhere"
    #change this to the magic # to alert you after
    emailtoomany=10
    mailfile="/tmp/mailcheck.txt"
    mailtest="/tmp/mailtest.txt"
    qnum=$(exim -bpc)
    if [ $qnum -gt $emailtoomany]
    then
    
    rm -rf $mailfile
    echo "Mail queue problem
    Queue is $qnum" >> $mailfile
    mailx -s "$SUBJ" $MYEMAIL < $mailfile
    rm -rf $mailfile
    fi
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice