This is an old revision of the document!


Convert voice Dial-peer config into a CSV Table

  • install sed for windows
  • get the running config of router(s)

<file winbatch export-dialpeer-to-csv.txt> : Author Gerard O'Rourke : Date 05/03/2019 : To export Dial-peer config into table format

: Note cannot handle dial-peer config which contain : a single quote (two quotes are ok) or “&”

cls @echo off REM Setting a Timestamp variable which can be used in a batch file FOR /f “tokens=1-4 delims=/ ” A IN ('date /t') DO ( set nday=A set nmonth=B set nyear=C ) set SORTDATE=%nyearnmonthnday% FOR /f “tokens=1-2 delims=: ” A IN ('time /t') DO ( set hour=A set min=B ) set SORTTIME=%hourmin% set TIMESTAMP=%sortdate%-%sorttime%

REM * REM START OF MAIN SCRIPT REM * set runningconfig=MyRouterConfigFile.txt echo . set /p runningconfig=Please Enter your Router Config File [%runningconfig%]? echo. set dialpeerlist=~%runningconfig%-dialpeerlist.txt set tempfile=~%runningconfig%-temp.txt set outputfile=dialpeer-table-export_%runningconfig%_%TIMESTAMP%.csv

REM create file list of voice dial-peer type %runningconfig% | find “dial-peer voice” > %dialpeerlist%

REM Print Header echo “dial-peer”,“description”,“translation-profile”,“preference”,“destination-pattern”,“session protocol”,“session target”,“voice-class codec”,“voice-class h323”,“dtmf-relay”,“fax”,“vad”,“direct-inward-dial”,“incoming”,“service” > %outputfile%

REM For Loop for each Dial-peer and create a temp file for just that dial-peer FOR /F “delims=” i IN (%dialpeerlist%) DO ( sed -n -e "/i/,/!/ p“ %runningconfig% >%tempfile% REM type %tempfile% echo | set /p=. call :exportdata )

echo. echo Finished! echo. echo Note - If any errors on console windows - capture them now, correct the input files and rerun echo. pause del %tempfile% del %dialpeerlist% exit

:exportdata SET description=. SET translation-profile=. SET preference=. SET destination-pattern=. SET session-protocol=. SET session-target=. SET voice-class-codec=. SET voice-class-h323=. SET dtmf-relay=. SET fax=. SET vad=. SET direct-inward-dial=. SET incoming=. SET service=.

FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "dial-peer"`) DO (SET dial-peer=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "description"`) DO (SET description=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "translation-profile"`) DO (SET translation-profile="F”) REM echo my translation profile is: translation-profile FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "preference"`) DO (SET preference=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "destination-pattern"`) DO (SET destination-pattern=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "session protocol"`) DO (SET session-protocol=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "session target"`) DO (SET session-target=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "voice-class codec"`) DO (SET voice-class-codec=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "voice-class h323"`) DO (SET voice-class-h323=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "dtmf-relay"`) DO (SET dtmf-relay=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "fax"`) DO (SET fax=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "vad"`) DO (SET vad=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "direct-inward-dial"`) DO (SET direct-inward-dial=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "incoming"`) DO (SET incoming=F) FOR /F “tokens=* USEBACKQ” F IN (`type %tempfile% ^| find "service"`) DO (SET service=F)

echo “%dial-peer%”,“%description%”,“%translation-profile%”,“%preference%”,“%destination-pattern%”,“%session-protocol%”,“%session-target%”,“%voice-class-codec%”,“%voice-class-h323%”,“%dtmf-relay%”,“%fax%”,“%vad%”,“%direct-inward-dial%”,“%incoming%”,“%service%” » %outputfile% exit /b </code>

  • tech-notes/scripts/dial-peer-config.1551799053.txt.gz
  • Last modified: 2019/03/05 15:17
  • by gerardorourke