May 5, 2010

IOS to JUNOS Style Configuration Converter Using AWK

Somebody resign.. I'll get extra work to do :) Yes, now I handle node called Content Service Gateway, another thing to learn, just be positive :)

Deep packet inspection configuration is so complex — No, that's hyperbolic, so many rules. The configuration is designed to charge everything necessary so You won't lose Your money. And the important thing is, keep it clean to avoid miss-charging :D

Beyond of that, Cisco IOS "sh run" configuration will make You headache when You read it. I'd like to say "No", I would not read it, better convert it :)


So I wrote this AWK script, that helps me so much. What it would do is display Cisco IOS "sh run" configuration style into Juniper JUNOS "display set" style :)

So, when you input following lines..

IOS sample configuration output

interface GigabitEthernet0/0
no ip address
no keepalive                                                      
standby use-bia                                                   
hold-queue 600 in
line con 0
password 7 123456789012345678
line vty 0 4
access-class telnet-acl in
password 7 123456789012345678

into this script

awk 'BEGIN{map=""; matc="";};
/^[a-z]/{map=$0; matc="";};
/^ [a-z]/{matc=$0;}; 
{if (map && matc){print map,matc;}; matc=""; }'

Will result this..

Cleaner and more readable output

interface GigabitEthernet0/0  no ip address
interface GigabitEthernet0/0  no keepalive
interface GigabitEthernet0/0  standby use-bia
interface GigabitEthernet0/0  hold-queue 600 in
line con 0  password 7 123456789012345678
line vty 0 4  access-class telnet-acl in
line vty 0 4  password 7 123456789012345678

Done! Let's analyze it..

Complex...

... !@#$%^& [HEADACHE]

9 comments:

  1. This one liner works gan :)

    awk '{if(NR==1){a=$0};if(NR>1) {print a,$0}}'

    ReplyDelete
  2. Ane nyoba kayak gini, Gan..

    awk '{if(NR==1){a=$0};if(NR>1) {print a,$0}}' CONFIG.TXT

    Kok ndak bisa ya?

    ReplyDelete
  3. disini bisa gan :)

    heric@:~$ awk '{if(NR==1){a=$0};if(NR>1) {print a,$0}}' tes

    ip csg map NEWS match url http://202.146.4.32/*
    ip csg map NEWS match url http://img.m.kompas.com/data/photo/*
    ip csg map NEWS match url http://202.146.4.86/*

    ReplyDelete
  4. Wah ketauan nih Gan..
    Kalau pake sample ane diatas, your one-liner is working, Gan. Tapi kalo pake real config, co-pas from CSG gak iso Gan..

    Soalnya ada BUG-nya nih Gan :)

    Pas dimasukin beginian...

    ardhy@zangetsu:~/tool/csg$ cat tes
    ip csg map NEWS
    match url http://202.146.4.32/*
    match url http://img.m.kompas.com/data/photo/*
    match url http://202.146.4.86/*
    ip csg map NEWS
    match url http://202.146.4.32/*
    match url http://img.m.kompas.com/data/photo/*
    match url http://202.146.4.86/*

    Keluarnya kaya begini, Gan...

    ardhy@zangetsu:~/tool/csg$ awk '{if(NR==1){a=$0};if(NR>1) {print a,$0}}' tes
    ip csg map NEWS match url http://202.146.4.32/*
    ip csg map NEWS match url http://img.m.kompas.com/data/photo/*
    ip csg map NEWS match url http://202.146.4.86/*
    ip csg map NEWS ip csg map NEWS
    ip csg map NEWS match url http://202.146.4.32/*
    ip csg map NEWS match url http://img.m.kompas.com/data/photo/*
    ip csg map NEWS match url http://202.146.4.86/*

    Mohon pencerahannya :)

    ReplyDelete
  5. Wah, bukan BUG, Gan.. sekrip-nya tidak tepat guna :)

    ReplyDelete
  6. one liner updated :D

    awk '{if($0!~/^ /){a=$0};if($0~/^ /){print a,$0}}'

    ReplyDelete
  7. agan2 ini memang membuat segan ...

    ReplyDelete