Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

bash - Correct mrtg cfgmaker file

mrtg cfgmaker does read incorrect values over SNMP V1 and V2 and I need to correct the resulting file.

I would like to run a script after creation and use sed if possible. Lines that needs to be corrected in my case are for LAG's and normal ports:

MaxBytes[switch01_lag_26]: 125000000 should go to MaxBytes[switch01_lag_26]: 250000000

(switch01_lag_26 can be switch01_lag_1 until switch01_lag_26)

MaxBytes[switch01_g1]: 12500000 should go to MaxBytes[switch01_g1]: 125000000

(switch01_g1 can be switch01_g1 until switch01_g16)

What sed patterns I have to use to analyze if its a lag or port in the square brackets and then replace the number after the : ?

The html part should show the correct speed if possible too, this is original for port g1:

<h1>Traffic Analysis for g1-- switch01</h1>
             <div id="sysdetails">
                        <table>
                                <tr>
                                        <td>System:</td>
                                        <td>switch01</td>
                                </tr>
                                <tr>
                                        <td>Maintainer:</td>
                                        <td></td>
                                </tr>
                                <tr>
                                        <td>Description:</td>
                                        <td>1-Gigabit---Level  </td>
                                </tr>
                                <tr>
                                        <td>ifType:</td>
                                        <td>ethernetCsmacd (6)</td>
                                </tr>
                                <tr>
                                        <td>ifName:</td>
                                        <td>g1</td>
                                </tr>
                                <tr>
                                        <td>Max Speed:</td>
                                        <td>12.5 MBytes/s</td>
                                </tr>
                                <tr>
                                        <td>Ip:</td>
                                        <td>No Ip (No DNS name)</td>
                                </tr>
                        </table>
                </div>

and should read at the end (Line below "Max Speed" is changed):

<h1>Traffic Analysis for g1-- switch01</h1>
             <div id="sysdetails">
                        <table>
                                <tr>
                                        <td>System:</td>
                                        <td>switch01</td>
                                </tr>
                                <tr>
                                        <td>Maintainer:</td>
                                        <td></td>
                                </tr>
                                <tr>
                                        <td>Description:</td>
                                        <td>1-Gigabit---Level  </td>
                                </tr>
                                <tr>
                                        <td>ifType:</td>
                                        <td>ethernetCsmacd (6)</td>
                                </tr>
                                <tr>
                                        <td>ifName:</td>
                                        <td>g1</td>
                                </tr>
                                <tr>
                                        <td>Max Speed:</td>
                                        <td>125.0 MBytes/s</td>
                                </tr>
                                <tr>
                                        <td>Ip:</td>
                                        <td>No Ip (No DNS name)</td>
                                </tr>
                        </table>
                </div>

This is original for LAG 1:

<h1>Traffic Analysis for lag 1 -- switch01</h1>
                <div id="sysdetails">
                        <table>
                                <tr>
                                        <td>System:</td>
                                        <td>switch01</td>
                                </tr>
                                <tr>
                                        <td>Maintainer:</td>
                                        <td></td>
                                </tr>
                                <tr>
                                        <td>Description:</td>
                                        <td>lag-1  </td>
                                </tr>
                                <tr>
                                        <td>ifType:</td>
                                        <td>IEEE 802.3ad Link Aggregate (161)</td>
                                </tr>
                                <tr>
                                        <td>ifName:</td>
                                        <td>lag 1</td>
                                </tr>
                                <tr>
                                        <td>Max Speed:</td>
                                        <td>125.0 MBytes/s</td>
                                </tr>
                                <tr>
                                        <td>Ip:</td>
                                        <td>No Ip (No DNS name)</td>
                                </tr>
                        </table>
                </div>

which should read at the end (Line below "Max Speed" is changed):

<h1>Traffic Analysis for lag 1 -- switch01</h1>
                <div id="sysdetails">
                        <table>
                                <tr>
                                        <td>System:</td>
                                        <td>switch01</td>
                                </tr>
                                <tr>
                                        <td>Maintainer:</td>
                                        <td></td>
                                </tr>
                                <tr>
                                        <td>Description:</td>
                                        <td>lag-1  </td>
                                </tr>
                                <tr>
                                        <td>ifType:</td>
                                        <td>IEEE 802.3ad Link Aggregate (161)</td>
                                </tr>
                                <tr>
                                        <td>ifName:</td>
                                        <td>lag 1</td>
                                </tr>
                                <tr>
                                        <td>Max Speed:</td>
                                        <td>250.0 MBytes/s</td>
                                </tr>
                                <tr>
                                        <td>Ip:</td>
                                        <td>No Ip (No DNS name)</td>
                                </tr>
                        </table>
                </div>

I can change all speeds in HTML using sed -i 's/([0-9.]+) MBytes/125.0 MBytes/' /switch01.cfg but this changes for LAG's too. How to detect if the HTML part belongs to a LAG?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...