Ivo has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone,
I am pulling out cli output with expect script from Cisco box in the following format:</>
Friday April 25 21:06:25 UTC 2014 Total Subscribers: 970260 Active: 86806 Dormant: + 883454 pdsn-simple-ipv4: 212 pdsn-simple-ipv6: + 0 pdsn-mobile-ip: 539792 ha-mobile-ipv6: + 0 hsgw-ipv6: 234943 hsgw-ipv4: + 1977 hsgw-ipv4-ipv6: 192328 pgw-pmip-ipv6: + 0 pgw-pmip-ipv4: 0 pgw-pmip-ipv4-ipv6: + 0 pgw-gtp-ipv6: 0 pgw-gtp-ipv4: + 0 pgw-gtp-ipv4-ipv6: 0 sgw-gtp-ipv6: + 0 sgw-gtp-ipv4: 0 sgw-gtp-ipv4-ipv6: + 0 sgw-pmip-ipv6: 0 sgw-pmip-ipv4: + 0 sgw-pmip-ipv4-ipv6: 0 pgw-gtps2b-ipv4: + 0 pgw-gtps2b-ipv6: 0 pgw-gtps2b-ipv4-ipv6: + 0 mme: 0 henbgw: 0 henbgw-sg: + 0 ipsg-rad-snoop: 0 ipsg-rad-server: + 0 ha-mobile-ip: 0 ggsn-pdp-type-ppp: + 0 ggsn-pdp-type-ipv4: 0 lns-l2tp: + 0 ggsn-pdp-type-ipv6: 0 ggsn-pdp-type-ipv4v6: + 0 ggsn-mbms-ue-type-ipv4: 0 pdif-simple-ipv4: 0 pdif-simple-ipv6: 0 pdif-mobile-ip: + 0 wsg-simple-ipv4: 0 wsg-simple-ipv6: + 0 pdg-simple-ipv4: 0 ttg-ipv4: + 0 pdg-simple-ipv6: 0 ttg-ipv6: + 0 femto-ip: 0 epdg-pmip-ipv6: 0 epdg-pmip-ipv4: + 0 epdg-pmip-ipv4-ipv6: 0 epdg-gtp-ipv6: 0 epdg-gtp-ipv4: + 0 epdg-gtp-ipv4-ipv6: 0 sgsn: 0 sgsn-pdp-type-ppp: + 0 sgsn-pdp-type-ipv4: 0 sgsn-pdp-type-ipv6: + 0 sgsn-pdp-type-ipv4-ipv6: 0 type not determined: + 1008 sgsn-subs-type-gn: 0 sgsn-subs-type-s4: + 0 sgsn-pdp-type-gn: 0 sgsn-pdp-type-s4: + 0 asngw-simple-ipv4: 0 asngw-simple-ipv6: + 0 asngw-mobile-ip: 0 asngw-non-anchor: 0 asngw-auth-only: + 0 phsgw-simple-ipv4: 0 phsgw-simple-ipv6: + 0 phsgw-mobile-ip: 0 phsgw-non-anchor: 0 cdma 1x rtt sessions: 0 cdma evdo sessions: + 6538 cdma evdo rev-a sessions: 963722 cdma 1x rtt active: + 0 cdma evdo active: 240 cdma evdo rev-a active: + 86566 asnpc-idle-mode: 0 phspc-sleep-mode: + 0 hnbgw: 0 hnbgw-iu: + 0 bng-simple-ipv4: 0 pcc: 0 in bytes dropped: 321802752 out bytes dropped: + 1402973 in packet dropped: 1884423 out packet dropped: + 6152 in packet dropped zero mbr: 0 out packet dropped zero m +br: 0 in bytes dropped ovrchrgPtn: 0 out bytes dropped ovrchrg +Ptn: 0 in packet dropped ovrchrgPtn: 0 out packet dropped ovrchr +gPtn: 0 ipv4 ttl exceeded: 56873 ipv4 bad hdr: + 5668 ipv4 bad length trim: 1098347 ipv4 frag failure: 0 ipv4 frag sent: + 803578 ipv4 in-acl dropped: 1437985 ipv4 out-acl dropped: + 0 ipv6 bad hdr: 55 ipv6 bad length trim: + 267 ipv6 in-acl dropped: 0 ipv6 out-acl dropped: + 0 ipv4 in-css-down dropped: 0 ipv4 out-css-down dropped +: 0 ipv4 out xoff pkt dropped: 0 ipv6 out xoff pkt dropped +: 0 ipv4 xoff bytes dropped: 0 ipv6 xoff bytes dropped: + 0 ipv4 out no-flow dropped: 0 ipv4 early pdu rcvd: 0 ipv4 icmp packets dropped +: 0 ipv6 input ehrpd-access drop: 0 ipv6 output ehrpd-access +drop: 0 dormancy count: 113523050 handoff count: + 2680943 pdsn fwd dynamic flows: 16211 pdsn rev dynamic flows: + 15046 fwd static access-flows: 0 rev static access-flows: + 0 pdsn fwd packet filters: 14869 pdsn rev packet filters: + 14869 traffic flow templates: 6946
I would like to convert it in CSV file with column headers the fileds with the text ending with : and 1st line the numbers after the texts. Also the first column should be the date. The expect script runs every H and I would like to put the data into MySQL database from the .csv file. Please help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing cli output into .csv
by davido (Cardinal) on Apr 26, 2014 at 01:44 UTC | |
by Ivo (Initiate) on Apr 26, 2014 at 10:48 UTC | |
|
Re: Parsing cli output into .csv
by CountZero (Bishop) on Apr 25, 2014 at 21:56 UTC | |
by erix (Prior) on Apr 26, 2014 at 06:09 UTC | |
by Ivo (Initiate) on Apr 26, 2014 at 10:42 UTC | |
by erix (Prior) on Apr 26, 2014 at 11:06 UTC | |
|
Re: Parsing cli output into .csv
by wjw (Priest) on Apr 26, 2014 at 05:39 UTC | |
by Ivo (Initiate) on Apr 26, 2014 at 10:56 UTC | |
by wjw (Priest) on Apr 26, 2014 at 19:07 UTC | |
by Ivo (Initiate) on Apr 26, 2014 at 10:38 UTC |