1

Junos のような構成データを "CSV のような" データ (タブで区切られたもの) にエクスポートして戻すスクリプトが必要です。サンプル(および知る限り十分な)入力は次のようになります。

firewall {
    filter protect {
        term "protocol bgp" {
            from {
                prefix-list {
                    bgp-peers;
                }
                protocol tcp; ## Any ideas how to preserve comments in output?
                port bgp;
            }
            then accept;
        }
        term protocol_ntp {
            from {
                prefix-list {
                    "protocol ntp";
                }
                protocol udp;
                port ntp;
            }
            then accept;
        }
    }
}

予想される出力は次のようになります (バー "|" は、タブが予想される場所を示します)。

firewall|filter protect|term "protocol bgp"|from|prefix-list|bgp-peers;
firewall|filter protect|term "protocol bgp"|from|protocol tcp;
firewall|filter protect|term "protocol bgp"|from|port bgp;
firewall|filter protect|term "protocol bgp"|then accept;
firewall|filter protect|term protocol_ntp|from|prefix-list|"protocol ntp";
firewall|filter protect|term protocol_ntp|from|protocol udp;
firewall|filter protect|term protocol_ntp|from|port ntp;
firewall|filter protect|term protocol_ntp|then accept;

一見、問題は非常に簡単に見えますが、二重引用符のせいではありません。この問題は、余分な二重引用符の処理により、「ツリーからテーブルへ」および「テーブルからツリーへ」の問題に縮小できるIMHOです私は正直にそれを正しく行うことを知りません...

私は次の人気順のソリューションを好むでしょう (私にとって): in sed(1)(非常に高速である可能性があります)、in awk(1)(私にとって前のものほど良くない)、in perl(1)(理由はありません。単純な Perl のみを使用しstrictwarningsモジュールのみをソースとして使用する場合) ) またはANSI Cで追加のライブラリを使用せず、ベースのみ (ここでパーサーを書きたいと思う人はいないと思いますが、誰も知りません)。

4

1 に答える 1

0

これは、JunOS が組み込みでサポートしている XML からの変換がはるかに簡単です。

show configuration | display xml

またはさらに良いことに、試してください

show configuration | display set
于 2011-05-25T17:19:55.567 に答える