bash - awk command to match multiple patterns -
i using awk command find entries in log file between 2 different times. have used command, , works:
awk '$0 >= "oct 04 12:00:00" && $0 <= "oct 04 12:30:00"' /var/log/messages
i want know how can search specific port allowed or blocked during time. example: if searching port 22 blocked between 12:00 12:30, how can search using awk command?
content of /var/log/messages
file:
nov 5 8:44:30 system1 kernel [022525 252748] output dropped=eth0 out= mac=ff:ff:ff:ff:ff:ff:01:00:25:97:b2:47:01:00 src=10.0.0.1 dst=192.168.4.141 len=221 tos=0x00 prec=0x00 ttl=128 id=23315 proto=udp spt=183 dpt=183 len=209
the entries in log file similar above. want know how can match information between, let's say, 12:00 12:30 spt=80 , dpt=80
you can add more conditions &&
doing dates. can put regular expression between 2 forward slashes match against whole line/record.
awk '/port 22 (blocked|allowed)/ && $0 >= "oct 04 12:00:00" && $0 <= "oct 04 12:30:00"' /var/log/messages
of course can use parentheses , combinations of logical , (&&
) and/or or (||
) if need more complex rules.
i want know how can match information between, let's say, 12:00 12:30 spt=80 , dpt=80
following explanation above, add /spt=80/ && /dpt=80/ && ...
conditions. note example line showed won't match, has spt , dpt values not 80 143.
and btw, keep in mind way filter date (for example $0 >= "oct 04 12:00:00" && $0 <= "oct 04 12:30:00"
) may not work dates crossing month boundaries, example lower bound in nov
higher bound in dec
not work.
Comments
Post a Comment