F
Facco Eloelo
I want to get the "inputrate" and the "outputrate" from a router's log(using
show command).and the outputfile looks like:
1,1000,0
2,3000,2000
....
It should be very easy.But the code doesn't work.can anybody help me?thanks in
advance.
#########code begin##################
#!/usr/bin/perl
$infile='d:\routertest.log';
$outfile='d:\output';
open(IN, "< $infile") or die "Couldn't open $infile for reading: $!";
open(OUT, "> $outfile") or die "Couldn't open $outfile for reading: $!";
@line=<IN>;
$num=@line;
$count=1;
for($i=0;$i<$num;$i++)
{
if(chomp($line[$i]) eq "r1-b-sdnn>show int fa1/1/0")
{
@inputrate=split(/''/,$line[$i+14]);
@outrate=split(/''/,$line[$i+1]);
print OUT "$count,$inputrate[4],$outputrate[4]";
$count++;
}
}
##############code end##########################
################d:\routertest.log##############
r1-b-sdnn>show int fa1/1/0
FastEthernet1/1/0 is up, line protocol is up
Hardware is cyBus FastEthernet Interface, address is 22211.d126.2898 (bia
0072.7176.2928)
Description: to-580-p
Internet address is 61.179.255.202/30
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec, rely 255/255, load 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s, 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters never
Queueing strategy: fifo
Output queue 0/40, 0 drops; input queue 1/75, 0 drops, 54 flushes
5 minute input rate 1000 bits/sec, 1 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
31321654 packets input, 3593026896 bytes, 0 no buffer
Received 13476682 broadcasts, 1 runts, 0 giants, 0 throttles
31 input errors, 0 CRC, 0 frame, 0 overrun, 31 ignored
0 watchdog, 0 multicast
0 input packets with dribble condition detected
25753387 packets output, 3750041951 bytes, 0 underruns
0 output errors, 0 collisions, 6 interface resets
0 babbles, 0 late collision, 0 deferred
10 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out
r1-b-sdnn>show int fa1/1/0
FastEthernet1/1/0 is up, line protocol is up
Hardware is cyBus FastEthernet Interface, address is 0902.7d16.8828 (bia
0102.7616.2228)
Description: to-580-p
Internet address is 35.179.255.202/30
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec, rely 255/255, load 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s, 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters never
Queueing strategy: fifo
Output queue 0/40, 0 drops; input queue 2/75, 0 drops, 54 flushes
5 minute input rate 3000 bits/sec, 3 packets/sec
5 minute output rate 2000 bits/sec, 3 packets/sec
31321698 packets input, 3593036917 bytes, 0 no buffer
Received 13476696 broadcasts, 1 runts, 0 giants, 0 throttles
31 input errors, 0 CRC, 0 frame, 0 overrun, 31 ignored
0 watchdog, 0 multicast
0 input packets with dribble condition detected
25753446 packets output, 3750058041 bytes, 0 underruns
0 output errors, 0 collisions, 6 interface resets
0 babbles, 0 late collision, 0 deferred
10 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out
r1-b-sdnn>show int fa1/1/0
FastEthernet1/1/0 is up, line protocol is up
Hardware is cyBus FastEthernet Interface, address is 0002.7016.2028 (bia
1002.0916.2028)
Description: to-580-p
Internet address is 78.179.255.202/30
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec, rely 255/255, load 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s, 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters never
Queueing strategy: fifo
Output queue 0/40, 0 drops; input queue 3/75, 0 drops, 54 flushes
5 minute input rate 3000 bits/sec, 5 packets/sec
5 minute output rate 3000 bits/sec, 5 packets/sec
31321765 packets input, 3593045770 bytes, 0 no buffer
Received 13476706 broadcasts, 1 runts, 0 giants, 0 throttles
31 input errors, 0 CRC, 0 frame, 0 overrun, 31 ignored
0 watchdog, 0 multicast
0 input packets with dribble condition detected
25753528 packets output, 3750073394 bytes, 0 underruns
0 output errors, 0 collisions, 6 interface resets
0 babbles, 0 late collision, 0 deferred
10 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out
#####################code end###############################
show command).and the outputfile looks like:
1,1000,0
2,3000,2000
....
It should be very easy.But the code doesn't work.can anybody help me?thanks in
advance.
#########code begin##################
#!/usr/bin/perl
$infile='d:\routertest.log';
$outfile='d:\output';
open(IN, "< $infile") or die "Couldn't open $infile for reading: $!";
open(OUT, "> $outfile") or die "Couldn't open $outfile for reading: $!";
@line=<IN>;
$num=@line;
$count=1;
for($i=0;$i<$num;$i++)
{
if(chomp($line[$i]) eq "r1-b-sdnn>show int fa1/1/0")
{
@inputrate=split(/''/,$line[$i+14]);
@outrate=split(/''/,$line[$i+1]);
print OUT "$count,$inputrate[4],$outputrate[4]";
$count++;
}
}
##############code end##########################
################d:\routertest.log##############
r1-b-sdnn>show int fa1/1/0
FastEthernet1/1/0 is up, line protocol is up
Hardware is cyBus FastEthernet Interface, address is 22211.d126.2898 (bia
0072.7176.2928)
Description: to-580-p
Internet address is 61.179.255.202/30
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec, rely 255/255, load 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s, 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters never
Queueing strategy: fifo
Output queue 0/40, 0 drops; input queue 1/75, 0 drops, 54 flushes
5 minute input rate 1000 bits/sec, 1 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
31321654 packets input, 3593026896 bytes, 0 no buffer
Received 13476682 broadcasts, 1 runts, 0 giants, 0 throttles
31 input errors, 0 CRC, 0 frame, 0 overrun, 31 ignored
0 watchdog, 0 multicast
0 input packets with dribble condition detected
25753387 packets output, 3750041951 bytes, 0 underruns
0 output errors, 0 collisions, 6 interface resets
0 babbles, 0 late collision, 0 deferred
10 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out
r1-b-sdnn>show int fa1/1/0
FastEthernet1/1/0 is up, line protocol is up
Hardware is cyBus FastEthernet Interface, address is 0902.7d16.8828 (bia
0102.7616.2228)
Description: to-580-p
Internet address is 35.179.255.202/30
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec, rely 255/255, load 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s, 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters never
Queueing strategy: fifo
Output queue 0/40, 0 drops; input queue 2/75, 0 drops, 54 flushes
5 minute input rate 3000 bits/sec, 3 packets/sec
5 minute output rate 2000 bits/sec, 3 packets/sec
31321698 packets input, 3593036917 bytes, 0 no buffer
Received 13476696 broadcasts, 1 runts, 0 giants, 0 throttles
31 input errors, 0 CRC, 0 frame, 0 overrun, 31 ignored
0 watchdog, 0 multicast
0 input packets with dribble condition detected
25753446 packets output, 3750058041 bytes, 0 underruns
0 output errors, 0 collisions, 6 interface resets
0 babbles, 0 late collision, 0 deferred
10 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out
r1-b-sdnn>show int fa1/1/0
FastEthernet1/1/0 is up, line protocol is up
Hardware is cyBus FastEthernet Interface, address is 0002.7016.2028 (bia
1002.0916.2028)
Description: to-580-p
Internet address is 78.179.255.202/30
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec, rely 255/255, load 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s, 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:00, output 00:00:00, output hang never
Last clearing of "show interface" counters never
Queueing strategy: fifo
Output queue 0/40, 0 drops; input queue 3/75, 0 drops, 54 flushes
5 minute input rate 3000 bits/sec, 5 packets/sec
5 minute output rate 3000 bits/sec, 5 packets/sec
31321765 packets input, 3593045770 bytes, 0 no buffer
Received 13476706 broadcasts, 1 runts, 0 giants, 0 throttles
31 input errors, 0 CRC, 0 frame, 0 overrun, 31 ignored
0 watchdog, 0 multicast
0 input packets with dribble condition detected
25753528 packets output, 3750073394 bytes, 0 underruns
0 output errors, 0 collisions, 6 interface resets
0 babbles, 0 late collision, 0 deferred
10 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out
#####################code end###############################