View realtime list of connections to Postfix
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.
Related videos on Youtube
Arammm
Updated on September 18, 2022Comments
-
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 almost 7 yearsI don't understand the down-votes... What's wrong with this question?
-
Vlad from Moscow about 4 yearsWhat is the operator the compiler refers to? There is no binary bitwise operator in the presented code.
-
Jabberwocky about 4 yearsI don't see and bitwise operator in your code.
-
David Ranieri about 4 years
isdigit[i]
-->isdigit(str[i])
, but with a castisdigit((unsigned char)str[i])
, see why the cast: stackoverflow.com/questions/17975913/… -
Adrian Mole about 4 years
isdigit[i]
is just plain wrong! You need an argument list forisdigit
and you probably want to passstr[i]
rather thani
. -
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 about 4 yearsThere are at least three syntax errors in your
if
statement, so I guess Clang Tidy gets a bit confused ... I certainly did! -
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 withisdigit
. But, from the compiler’s perspective, that is syntactically okay; it is a semantic error, not a syntax error. -
Eric Postpischil about 4 yearsShow 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 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 about 4 years@EricPostpischil good point thanks
-
Adrian Mole about 4 years@EricPostpischil Funnily, if I define
ISDIGIT(X)
as a macro, then modifying the OP's code only to changeisdigit
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 about 4 years"how can I fix it?" -->
if((!isalpha(str[i]))&&((!isdigit[i])))
-->if(!isalnum((unsigned char) str[i]))
-
-
Ryan Griggs almost 10 yearsAny way to tell when these connections are disconnected?
-
Michael Hampton almost 10 yearsThe same way. They appear right in the same log!
-
Ryan Griggs almost 7 yearsThis 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 about 4 years@AdrianMole So why does it give me a clang tidy marking? this hits my OCD real hard.
-
Eric Postpischil about 4 yearsThey should cast the arguments to
unsigned char
before passing them to the character classification functions. -
Eric Postpischil about 4 yearsWhat C implementation are you using, and how do you know it is not using macros for these functions?
-
Adrian Mole about 4 yearsI tested it using
clang-cl
and, when I right-click onisdigit
and go to its definition, I see this:_Check_return_ _CRT_JIT_INTRINSIC _ACRTIMP int __cdecl isdigit(_In_ int _C);
-
Lundin about 4 years@EricPostpischil Not necessarily, these functions are designed to accept
EOF
as valid input. -
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 toint
) is definitely best practice, I didn't consider it relevant to this problem. -
Eric Postpischil about 4 years@Lundin: That is not relevant. If OP had an
int
that contained either anunsigned char
value orEOF
, I would not have made that comment. But they do not, they have elements from an array ofchar
. If any of those are negative, the behavior is not defined by the C standard. Casting tounsigned char
is a fix for that. If they had anint
that might contain either achar
value orEOF
, it would not be a fix, but they do not. -
sastorsl over 3 yearsBare in mind that
tail -f <anyfile>
will not follow a logfile which is replaced, i.e. bylogrotate
. The GNU tail has thetail -F
option which will follow the filename, even if it is replaced.