One.liner 
Author Message
 One.liner

Hi!
I have got an oneliner on the Debian machine for to read from my logs:

<cut>
egrep 'Packet log.*(input DENY eth1|input REJECT eth1)' /var/log/messages |
awk '{split($12,x,":")split($13,y,":");print x[1]"\t\tMy Port"y[2]}' | sort
-g > 1.tmp

<cut>
After some sorting and twisting I get the output:

123.123.123.123         My Port 21
Remote machine          my port at home

And everything is fine... Almost

I would like to get the output to be like

123.123.123.123         My Port 21      FTP
123.123.123.110         My Port 23      Telnet

I guess that I need some if- statement  

if(y[2]=="21") print "FTP"
or
if(y[2]=="23") print "Telnet"

etc.... Is this possible to do???
Hopes for help
/Micke                                  



Sat, 02 Aug 2003 02:40:07 GMT  
 One.liner

Quote:

>I guess that I need some if- statement

>if(y[2]=="21") print "FTP"
>or
>if(y[2]=="23") print "Telnet"

>etc.... Is this possible to do???
>Hopes for help
>/Micke

You could use an array, maybe using the data from /etc/services.


Sat, 02 Aug 2003 10:13:13 GMT  
 One.liner

Quote:

>Hi!
>I have got an oneliner on the Debian machine for to read from my logs:

><cut>
>egrep 'Packet log.*(input DENY eth1|input REJECT eth1)' /var/log/messages |
>awk '{split($12,x,":")split($13,y,":");print x[1]"\t\tMy Port"y[2]}' | sort
>-g > 1.tmp

><cut>
>After some sorting and twisting I get the output:

>123.123.123.123             My Port 21
>Remote machine              my port at home

>And everything is fine... Almost

>I would like to get the output to be like

>123.123.123.123             My Port 21      FTP
>123.123.123.110             My Port 23      Telnet

>I guess that I need some if- statement  

>if(y[2]=="21") print "FTP"
>or
>if(y[2]=="23") print "Telnet"

>etc.... Is this possible to do???
>Hopes for help
>/Micke                                      

Yes, but it might be most compact to use the ? : operator.
Something like this (untested) nested assignment should work:

awk '{split($12,x,":")split($13,y,":");
print x[1]"\t\tMy Port"y[2]"\t\t"
mode=(y[2]=="21"?"FTP":(y[2]=="23"?Telnet":""));

Quote:
}' | sort

Chuck Demas

P.S. You could have used if statements to assign mode and then
printed it, but I think that in this case using the ? : operator
is more elegant. :-)

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Sat, 02 Aug 2003 12:13:43 GMT  
 One.liner
If you want to be really tricky, and avoid the "if" altogether, this works:

Quote:
> egrep 'Packet log.*(input DENY eth1|input REJECT eth1)' /var/log/messages
|
> awk

'BEGIN{port[21]="FTP";port[22]="Telnet"}{split($12,x,":")split($13,y,":");pr
int x[1]"\t\tMy Port"y[2] port[y[2]]}' | sort

Programming note: in most (probably all) implementations, uninitialized
array members in awk simply print as "", so there is no need to worry about
ports other than 21 or 22 causing problems.


Quote:

> Hi!
> I have got an oneliner on the Debian machine for to read from my logs:

> <cut>
> egrep 'Packet log.*(input DENY eth1|input REJECT eth1)' /var/log/messages
|
> awk '{split($12,x,":")split($13,y,":");print x[1]"\t\tMy Port"y[2]}' |
sort
> -g > 1.tmp

> <cut>
> After some sorting and twisting I get the output:

> 123.123.123.123 My Port 21
> Remote machine my port at home

> And everything is fine... Almost

> I would like to get the output to be like

> 123.123.123.123 My Port 21 FTP
> 123.123.123.110 My Port 23 Telnet

> I guess that I need some if- statement

> if(y[2]=="21") print "FTP"
> or
> if(y[2]=="23") print "Telnet"

> etc.... Is this possible to do???
> Hopes for help
> /Micke



Tue, 05 Aug 2003 12:11:23 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. APL one-liner needed for new novel

2. J One Liners

3. one liner awk

4. aplit line - one liner

5. Looking for AWK/SED one-liners

6. One Liners

7. LOGO-L> One-liners :-)

8. LOGO-L> one-liners

9. LOGO-L> one-liner

10. LOGO-L> Re: one-liners

11. LOGO-L> many one-liners

12. LOGO-L> legal/illegal one-liners correction

 

 
Powered by phpBB® Forum Software