Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading From a File

Status
Not open for further replies.

MyFlight

Technical User
Feb 4, 2002
193
Hello,
I am working with a brand New Siemens switch via Telnet and need to list out all of my trunks. The list gives the Port addresses in hyphen seperated format. I then need to take these numbers (from 3 seperate files and send them in a comma seperated format with a virtual trunk number assigned.

The virtual trunk number would need to count up from XX. Where XX is defined by the user and can be a number from 3 to 10 digits in length.

I beleive there are one of two way s of doing this. First the files are downloaded via ProCom. Then I have the option of formatting these files using MS-Excel or of leaving it all to ProComm. I need to seperate these number to individual place holders Example: 1-1-91-1 becomes 1,1,91,1

Next and a ",0,"
then add the Virtual Trunk Number ,XX
finish off with a Semicolon and an Enter so I end up with the following:

ADD-FBTN:TRKNO,1,1,91,2,0,5101001;
ADD-FBTN:TRKNO,1,14,121,23,0,5101002;


Download file Examples (the Three Files Downloaded)

TDCSU.txt EXAMPLE

ADD -TACSU: 1-1-91-1, , 8, 8, 0, 0, 40, 1, 1,
, 8, 0," ",ADD-
0, , 2,1,EMPTY,0 ,
NONE, NONE, 0,EC&G729 &G711 ,
" ", 0, GDTR,
0, CO,Y ,TC ,LPSTR ,
0, ,0,0, 1, 1, 1, 0, DTMF-DTMF , 0-0 , 0;
ADD -TACSU: 1-14-121-23, , 8, 8, 0, 0, 40, 1, 1,
, 8, 0," ",
0, , 2,1,EMPTY,0 ,
NONE, NONE, 0,EC&G729 &G711 ,
" ", 0, GDTR,
0, CO,Y ,TC ,LPSTR ,
0, ,0,0, 1, 1, 1, 0, DTMF-DTMF , 0-0 , 0;



TDCSU.txt EXAMPLE

ADD-TDCSU:NEW ,1-02-049-0,92,91,0,0,90,25,1," ",91
,PSS1V2,8,,NONE,,,,GDTR,Y,TIE,NONE,N,0,
,,,,,
,31,MANY,91,0,1,1,EMPTY,92,5,N,
,,,,,16,8,1,10,,EC&G711&G729
,"",91,CIR,Y,S0CONN,
,Y,Y,0,N;
ADD-TDCSU:NEW ,1-02-049-1,92,91,0,0,90,25,1," ",91
,PSS1V2,8,,NONE,,,,GDTR,Y,TIE,NONE,N,0,
,,,,,
,31,MANY,91,0,1,1,EMPTY,92,5,N,
,,,,,16,8,1,10,,EC&G711&G729
,"",91,CIR,Y,S0CONN,
,Y,Y,0,N;


TSCSU.txt EXAMPLE

NONE AVAILABLE at this time


I started working on a script based on previous use, but got way out of my element. Here is what I have so far.


#define WorkDir "C:\Temp Data Files\Raw Data\"
#define SaveDir "C:\Temp Completed Reports\"
#define OldFname "TACSU.txt"
#define sEnter "^M"
#define svTrunkDone " NEW VIRTUAL TRUNK ASSIGNED "
#define svTrunkProblem " NO VIRTUAL TRUNK NUMBER "

Proc main

integer iLen, ivar, cVtrunk, iVtrunk, vTrkNum
string fName = "Completed V Trunks.txt "
string sTok1, sLine, svTrkNum

if $CONNECTOPEN
; check for connection...

sdlginput "Starting Virtual Trunk Number" "Enter the FIRST Virtual Trunk Number:" svTrkNum
atoi svTrkNum vTrkNum

chdir WorkDir
isfile OldFname ivar ; Verifies that File does Exist.
if SUCCESS
fopen 1 OldFname READWRITE TEXT
chdir SaveDir
fopen 2 fName CREATE TEXT
pause 2
transmit "^M"
cVtrunk = 0
iVtrunk = 0
while not feof 1
fgets 1 sLine
strlen sLine iLen
; Assigns Text in First Field (From Text File) to Variable sTok1.
strtok sTok1 sLine " " 1
waitfor " <" 3
endproc


Any and all help would be greatly appreciated.

 
If you need to convert all hypens to commas in the initial string, then the best way to do that would be to use this command:

strreplace sVar "-" ","

instead of using strtok to break out the string and then combine it back together.

To add the additional information once you've read it in from the file, you could use either strcat or strfmt.


aspect@aspectscripting.com
 
KNOB,

Well here is the Script I have so far. I took out all the Transmit/Waitfor Commands, so I could test without being connected.


#define OldFname "HiPath 4000 Trunk List.txt"
Sample Text

1-2-91-4,5,6,7,8,9,10,11,12,13,14,0
1-1-191-23,0,8,8,0,0,10,11,12,13,14,0
1-1-61-2,0,8,8,0,0,10,11,12,13,14,0


#define WorkDir "C:\Temp Data Files\Reconfigured Data\"
#define SaveDir "C:\Temp Completed Reports\"
#define OldFname "HiPath 4000 Trunk List.txt"
#define sEnter "^M"
#define sComma ","
#define svTrunkDone " NEW VIRTUAL TRUNK ASSIGNED "
#define svTrunkProblem " NO VIRTUAL TRUNK NUMBER "
#define sStartCmd "ADD-FBTN:TRKNO"
#define sEndCmd ";"
#define sMidCmd ",0,"
Proc main
integer iLen, ivar, cVtrunk, iVtrunk, vTrkNum
string fName = "Completed V Trunks.txt "
string sTok1, sTok2, sTok3, sTok4, sTok5, sLine, svTrkNum, sTrunkCommand
;if $CONNECTOPEN
; ; check for connection...
sdlginput "Starting Virtual Trunk Number" "Enter the FIRST Virtual Trunk Number:" svTrkNum
chdir WorkDir
isfile OldFname ivar ; Verifies that File does Exist.
if SUCCESS
fopen 1 OldFname READWRITE TEXT
chdir SaveDir
fopen 2 fName CREATE TEXT
pause 2
transmit "^M"
cVtrunk = 0
iVtrunk = 0
while not feof 1
fgets 1 sLine
strlen sLine iLen
strtok sTok1 sLine "," 1
strreplace sTok1 "-" ","
strtok sTok2 sLine "," 2
strtok sTok3 sLine "," 3
strtok sTok4 sLine "," 4
strtok sTok5 sLine "," 5
atoi svTrkNum vTrkNum
vTrkNum ++
strcat sTrunkCommand sStartCmd
strcat sTrunkCommand sComma
strcat sTrunkCommand sTok1
strcat sTrunkCommand sMidCmd
strcat sTrunkCommand svTrkNum
strcat sTrunkCommand sEndCmd
itoa vTrkNum svTrkNum
usermsg "Test 1: `"%s`"!" sTrunkCommand
pause 1
; waitfor " <" 3
; transmit sTok1
; transmit "^M"
; waitfor " <" 3
; if FAILURE
; finsblock 2 17
; fputs 2 sVtrunkProblem
; iVtrunk ++
; else
; finsblock 2 17
; fputs 2 sVtrunkDone
; cVtrunk ++
; endif
endwhile
fclose 1
fclose 2
else
usermsg "Missing BCRS_STF.txt FILE"
exit
endif
;else
; usermsg "Lost Connection Please Try Again"
; exit
;endif
pause 1
; transmit "^M"
; waitfor " <" 3
capture OFF
chdir WorkDir
PAUSE 3
; if not delfile OldFname ; Delete the temporary file.
; errormsg "Couldn't delete `"%s`"!" OldFname
; else
; usermsg "`"%s`" deleted." OldFname
; endif
; hangup
usermsg "Boxes Message Alert: `"%s`"!" svTrkNum
usermsg "Virtual Trunks Assigned : '%d'" cVtrunk
usermsg "Virtual Trunks NOT Assigned: '%d'" iVtrunk
endproc



It should output the following:


ADD-FBTN:TRKNO,1,2,91,4,0,1001;
ADD-FBTN:TRKNO,1,1,191,23,0,1002;
ADD-FBTN:TRKNO,1,1,61,2,0,1003;


The FIRST Time it works Great. However when it goes to the 2nd line, I get is this all strung together after the 2nd and 3rd Lines:


ADD-FBTN:TRKNO,1,2,91,4,0,1001;ADD-FBTN:TRKNO,1,1,191,23,0,1002;ADD-FBTN:TRKNO,1,1,61,2,0,1003;



Any ideas what is wrong. As always your help is greatly appreciated.

 
Usually this occurs if you are modifying a value using strcat or another value and keep appending to a value instead of setting it to a null string before each run. I added this line:

sTrunkCommand = ""

just prior to the various strcat sTrunkCommand statements and that seems to have taken care of the problem.


aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top