[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [TEKNIK] bash - grep og regular expression



Mogens Melander skrev:

Dagens opgave går ud på, i bash-script, at trække ip-adressen ud af følgende
log entries.

Mar 19 12:45:48 styx sshd[19796]: Failed password for illegal user newsroom
from 213.133.99.19 port 33561 ssh2
Mar 19 12:45:48 styx sshd[19797]: Illegal user brian from 213.133.99.19

Regulære udtryk har aldrig været min stærke side, og jeg har en klar
fornemmelse af at denne opgave løses bedst af sådanne. Jeg kan klare
det med en kombination af grep|cut, men er overbevist om at det kan
klares enklere/mere elegant med det rette udtryk.

du kan f.eks. bruge awk eller perl der begge har regular expressions og kan manipulere med data. Jeg foretrækker "gawk" til simple tekst-ind og tekst-ud opgaver.


/: Failed password for illegal user newsroom from/ { # forhåbentlig nok match, ellers må tilføjes lidt mere
print $13; # udnyt at det er 13. felt (adskilt af blanktegn)
next;
}
/: Illegal user brian from/ {
print $10; # her er det 10. felt
next;
}


Erstart "newsromm" og "brian" med [^[:space:]]+ hvis det ikke er specifik de "user" du vil matche. (evt. [[:alnum]]+ hvis du ved user kun kan være bogstaver og cifre)






 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-04-01, 02:02 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *