Is there a simple command to find out the current number of messages per domain in the linux sendmail queue? mailq dumps out a verbose list, but it's not convenient for a quick overview.
I'm using Centos and sendmail.
mailq -v | egrep -v '^-' | get_domains.pl | sort | uniq -c
But the above command output is as following:
1 domain.com>
Above command did not fulfill my requirement, any help in this regard please.
Here is updated output:
domain.com> has 5 message(s)
domain.com.pk> has 1 message(s)
abc.com.pk> has 2 message(s)
xyz.coinfo.net.cn> has 1 message(s)
mmm.com> has 1 message(s)
Best Answer
Well, if you are going to use perl, might as well go all the way.
The following is a fairly imperfect way of counting the number of messages per domain:
Essentially, we send an output of the mailq command into an array and iterate. For each record in the array, we strip the leading and trailing spaces/newlines, and then split at the "@" sign. Then we insert domain as a key (if it doesn't exist) and then increment it in a hash. On the next try, it will simply increment the value if the same domain was found. From there, we loop through the hash and then print out the domain with the total number of matches.
The result:
Like I said, its not perfect, but it does the job. If nothing else, it will give you an idea of where to go from here.
Incidentally, since it appears you know perl, review of Perl's hash data structures will prove to be very useful:
http://www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/hash/
Or:
http://perldoc.perl.org/perldsc.html