How do I count the messages of Postfix's mailq?

68

Solution 1

I use this:

mailq | grep -c "^[A-F0-9]"

You can pipe the output of mailq through various other filters such as uniq, sort and wc to get other statistics.

Solution 2

either mailq | tail -n 1 or find /var/spool/postfix/deferred -type f | wc -l

both works

Share:
68
Marije Miedema
Author by

Marije Miedema

Updated on September 18, 2022

Comments

  • Marije Miedema
    Marije Miedema over 1 year

    I'm writing a full body detection script with automatic img safe when body is detected via webcam (logitech c170) using a RaspberryPi3, Opencv3 and Python3.5

    This is what I have so far

    import numpy as np
    import cv2
    import os
    
    
    def inside(r, q):
        rx, ry, rw, rh = r
        qx, qy, qw, qh = q
        return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh
    
    
    def draw_detections(img, rects, thickness = 1):
        for x, y, w, h in rects:
    
            pad_w, pad_h = int(0.15*w), int(0.05*h)
            cv2.rectangle(img, (x+pad_w, y+pad_h), (x+w-pad_w, y+h-pad_h), (0, 255, 0), thickness)
    
    
    if __name__ == '__main__':
    
        num = 0
        hog = cv2.HOGDescriptor()
        hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )
        cap=cv2.VideoCapture(0)
        previously_found = False
    
        while True:
            _,frame=cap.read()
            found,w=hog.detectMultiScale(frame, winStride=(8,8), padding=(32,32), scale=1.05)
            if all(found) and not previously_found:
                previously_found = True
                cv2.imwrite('/home/pi/jebenter/'+'opencv'+str(num)+'.jpg',frame)
                num = num+1
            elif not all(found):
                previously_found = False
    
            draw_detections(frame,found)
            cv2.imshow('feed',frame)
            ch = 0xFF & cv2.waitKey(1)
            if ch == 27:
                break
    
        cv2.destroyAllWindows()
    

    When executed I get the following error:

    Traceback (most recent call last):
      File "peopledetectF.py, line 30, in <module>
        if all(found) and not previously_found:
    ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()  
    

    I tried replacing the all with any, didn't work. I read something about using & and * instead of and or

    But do not really know how to apply this. Does someone know how to fix this?

  • andy
    andy almost 9 years
    This is not accurate. When the Postfix queue is empty, then run 'mailq', we will get "Mail queue is empty" which also match "^[0-9A-Z]". And in such a situation it is not accurate.
  • Ladadadada
    Ladadadada over 8 years
    A better regex is ^[A-F0-9] which correctly results in 0 when the mail queue is empty. I've edited the answer.
  • Geoffrey
    Geoffrey over 7 years
    How silly, the last line of the output is the count
  • rob
    rob over 6 years
    I get "682430 Kbytes in 26472 Requests." for the first one and "23" for the second one.
  • Marije Miedema
    Marije Miedema over 6 years
    Tried but I get the following error: Traceback (most recent call last): File "peopledetectF.py", line 30, in <module> if found.all() and not previously_found: AttributeError: 'tuple' object has no attribute 'all'
  • Mike Müller
    Mike Müller over 6 years
    Check the content of found. It is a tuple that contains a NumPy array. So maybe found[0].all() works.
  • Marije Miedema
    Marije Miedema over 6 years
    Tried but I'm now getting this. I just started working with python a week ago, I'm sorry if I'm stating obvious problems but I'm a bit lost (and on a deadline..) Traceback (most recent call last): File "peopledetectF.py", line 30, in <module> if found[0].all() and not previously_found: IndexError: tuple index out of range
  • Mike Müller
    Mike Müller over 6 years
    Does not make sense to me. Either the tuple is empty, than there is no such error message abou tall, or it contains a NumPy array, than it should be index-able.
  • Shawn Mathew
    Shawn Mathew over 6 years
    Awesome. Hopefully you made your deadline
  • royarisse
    royarisse over 2 years
    The second one only shows deferred messages, adding the active queue the counts should match up: find /var/spool/postfix/active /var/spool/postfix/deferred -type f | wc -l.