View realtime list of connections to Postfix

665

Solution 1

postfix logs each connection as it comes in, and the log lines look like

Jul  8 16:25:15 swiss postfix/smtpd[11127]: connect from some.host.or.other [192.0.2.1]

so you can tail -F your logfile (on my system it's /var/log/mail.log), use grep to filter the lines you want, and watch the live traffic.

Solution 2

The above poster is close.

tail allows you to see the last 10 lines in a file. The -f switch allows you to see new lines as they are appended to the maillog file.

cd /var/log

tail -f maillog

Ctrl+c to escape.

Seeing this is already written to a file called /var/log/maillog, not sure why you would want to create another file unless you are looking to extract specific information.

If you want to just read the maillog, use your favorite editor or do this:

less maillog

hitting the Enter (return) key will move the file down a single line at a time or you can hit the Page Down key for a full screen move.

HHitting the q key will escape you out.

Share:
665

Related videos on Youtube

Arammm
Author by

Arammm

Updated on September 18, 2022

Comments

  • Arammm
    Arammm almost 2 years

    I have a string char str[] (lets assume its not empty)

    When I perform the iteration:

    for(int i = 0; i<strlen(str);i++)
        {
            if((!isalpha(str[i]))&&((!isdigit[i])))
            {
                printf("something");
    
            }
        }
    

    I get the following marking:

    Clang-Tidy: Use of a signed integer operand with a binary bitwise operator
    

    Why is it occuring? and how can I fix it?

    • Ryan Griggs
      Ryan Griggs almost 7 years
      I don't understand the down-votes... What's wrong with this question?
    • Vlad from Moscow
      Vlad from Moscow about 4 years
      What is the operator the compiler refers to? There is no binary bitwise operator in the presented code.
    • Jabberwocky
      Jabberwocky about 4 years
      I don't see and bitwise operator in your code.
    • David Ranieri
      David Ranieri about 4 years
      isdigit[i] --> isdigit(str[i]), but with a cast isdigit((unsigned char)str[i]), see why the cast: stackoverflow.com/questions/17975913/…
    • Adrian Mole
      Adrian Mole about 4 years
      isdigit[i] is just plain wrong! You need an argument list for isdigit and you probably want to pass str[i] rather than i.
    • Eric Postpischil
      Eric Postpischil about 4 years
      @VladfromMoscow: The character classification macros are often implemented with macros which contain bitwise operators. If you voted down based on the lack of visible bitwise operators in the question, then you voted in error.
    • Adrian Mole
      Adrian Mole about 4 years
      There are at least three syntax errors in your if statement, so I guess Clang Tidy gets a bit confused ... I certainly did!
    • Eric Postpischil
      Eric Postpischil about 4 years
      @AdrianMole: There is only one error in the if statement that might be described as a syntax error. That is the use of brackets instead of parentheses with isdigit. But, from the compiler’s perspective, that is syntactically okay; it is a semantic error, not a syntax error.
    • Eric Postpischil
      Eric Postpischil about 4 years
      Show a minimal reproducible example. There is some question about the actual code producing this message. Also state precisely which C implementation you are using—preferably the full name and version of the C compiler and standard C library, but the name and version of the compiler at least.
    • Adrian Mole
      Adrian Mole about 4 years
      @EricPostpischil A good point - I was actually seeing other errors due to missing header files. See my answer, below - which may not have a very long lifetime!
    • Jabberwocky
      Jabberwocky about 4 years
      @EricPostpischil good point thanks
    • Adrian Mole
      Adrian Mole about 4 years
      @EricPostpischil Funnily, if I define ISDIGIT(X) as a macro, then modifying the OP's code only to change isdigit to uppercase (to invoke the macro) fails because it has no parameter list ... and, as such, is not recognized as the same macro.
    • chux - Reinstate Monica
      chux - Reinstate Monica about 4 years
      "how can I fix it?" --> if((!isalpha(str[i]))&&((!isdigit[i]))) --> if(!isalnum((unsigned char) str[i]))
  • Ryan Griggs
    Ryan Griggs almost 10 years
    Any way to tell when these connections are disconnected?
  • Michael Hampton
    Michael Hampton almost 10 years
    The same way. They appear right in the same log!
  • Ryan Griggs
    Ryan Griggs almost 7 years
    This only shows new connections as they happen. Not a list of all current active connections. Something like the 'top' command would be best, with a realtime display of all connections and their IP addresses.
  • Arammm
    Arammm about 4 years
    @AdrianMole So why does it give me a clang tidy marking? this hits my OCD real hard.
  • Eric Postpischil
    Eric Postpischil about 4 years
    They should cast the arguments to unsigned char before passing them to the character classification functions.
  • Eric Postpischil
    Eric Postpischil about 4 years
    What C implementation are you using, and how do you know it is not using macros for these functions?
  • Adrian Mole
    Adrian Mole about 4 years
    I tested it using clang-cl and, when I right-click on isdigit and go to its definition, I see this: _Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl isdigit(_In_ int _C);
  • Lundin
    Lundin about 4 years
    @EricPostpischil Not necessarily, these functions are designed to accept EOF as valid input.
  • Adrian Mole
    Adrian Mole about 4 years
    @EricPostpischil While I absolutely agree that casting to unsigned char (i.e. to prevent sign-extension when the argument is promoted to int) is definitely best practice, I didn't consider it relevant to this problem.
  • Eric Postpischil
    Eric Postpischil about 4 years
    @Lundin: That is not relevant. If OP had an int that contained either an unsigned char value or EOF, I would not have made that comment. But they do not, they have elements from an array of char. If any of those are negative, the behavior is not defined by the C standard. Casting to unsigned char is a fix for that. If they had an int that might contain either a char value or EOF, it would not be a fix, but they do not.
  • sastorsl
    sastorsl over 3 years
    Bare in mind that tail -f <anyfile> will not follow a logfile which is replaced, i.e. by logrotate. The GNU tail has the tail -F option which will follow the filename, even if it is replaced.