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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting data from a text file via a loop

Status
Not open for further replies.

jeditom

IS-IT--Management
Dec 3, 2003
23
0
0
US
In an eight step Telnet process which waits for queues then sends keystrokes, how do I get a loop in place for just one step, where the text inputed is drawn from a text file?

Script:

proc main
; TELNET INTO THE CONTROLLER
connectmanual telnet "89.1.16.105"
; CHOOSE 1 SELECT UNIT
waitfor "SELECT UNIT" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
waitquiet 3
transmit "1"
waitquiet 1
transmit "^M"

; CHOOSE 1 TO CHANGE THE SHELF
waitfor "SHELF=" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
waitquiet 1
transmit "^M"

; ENTER THE SHELF NUMBER
waitfor "ENTER SHELF : ^[[24;28H" Forever
transmit "3"
waitquiet 1
transmit "^M"

; CHOOSE 2 TO CHANGE THE SLOT
waitfor "ENTER SELECTION : " Forever
transmit "2"
waitquiet 1
transmit "^M"





;THIS STEP BELOW IS WHERE I NEED TO PULL FROM A DATA FILE!!!!




; ENTER THE SLOT NUMBER
waitfor "ENTER SLOT : ^[[24;27H" Forever
transmit "1"
waitquiet 1
transmit "^M"

; CHOOSE 3 TO ENTER THE SHELF AND SLOT CHOSEN
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "3"
waitquiet 1
transmit "^M"
waitquiet 2

; CHOOSE 7 FOR DIAL BACKUP
waitfor "DIAL BACKUP" forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "7"
waitquiet 1
transmit "^M"

; CHOOSE 1 TO GO TO DIAL BACKUP
waitquiet 1
waitfor " GO TO DIAL BACKUP" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
waitquiet 1
transmit "^M"

; CHOOSE 1 TO DIAL STORED NUMBER
waitquiet 1
waitfor "DIAL STORED NUMBER" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
waitquiet 1
transmit "^M"

; CHOOSE 1 TO DIAL THE FIRST STORED NUMBER
waitfor "ENTER NUMBER TO DIAL :" Forever
waitquiet 3
transmit "1"
waitquiet 1
transmit "^M"
waitquiet 1

endproc






 
Are you just reading one (the first) line from the text file, or will you be looping through the text file? Can you post which exact lines should be reading their input from the text file?


aspect@aspectscripting.com
 
The line that reads:

; ENTER THE SLOT NUMBER
waitfor "ENTER SLOT : ^[[24;27H" Forever
transmit "1"
waitquiet 1
transmit "^M"

It is the data transmitted during this step that will be pulled from a text file. All of the other steps will have the same keystrokes transmitted.
 
If you are just reading the first line from the file, then something like this would work:

waitfor "ENTER SLOT : ^[[24;27H" Forever
if fopen 0 "file.txt" READ TEXT
fgets 0 sLine
transmit sLine
waitquiet 1
transmit "^M"
endif

You would also need to add string sLine to the beginning of your script with your other variable declarations.


aspect@aspectscripting.com
 
KNOB, YOU TOTALLY ROCK!

But ... one last question (I hope)

How do i set it up to grab one OR two digit numbers from the text file? (the parameters are 1-15)

THANKS!!!!!
 
Fgets will grab the entire first line (minus carriage returns/linefeeds since the example used the TEXT flag with the fopen command), so as long as the information you need is all on the first line you should be OK.


aspect@aspectscripting.com
 
OH NO!

No matter what I do I cannot get two digits transmitted. If I do it manually with transmit lines I need to transit one digit, waitquiet 1, then transmit the second digit. I believe the delay exists on the Adtran controller I am telnetted into. Is there a way to modify the file below to address the delay I require?

; ENTER THE SLOT NUMBER
waitfor "ENTER SLOT : ^[[24;27H" Forever
if fopen 0 "data.txt" READ TEXT
fgets 0 sLine
transmit sLine
waitquiet 2
transmit "^M"
endif
 
You could try using the set txpace command to increase the transmit pacing (probably set at zero now) to 1000 millisecond just before the transmit command then set it back to its current value (can find this out using the fetch txpace command) after the transmit command.


aspect@aspectscripting.com
 
That worked great, THANKS!

The final piece of the puzzle is to loop the entire script below until the data.txt file has no more lines.

(The overall goal is to telnet in to the controller card and enter different slots on the rack (as per the data.txt file) and executing the steps to put that modem in dial backup. Once we have dialed from each slot we want the script to end execution)

The loop needs to begin after the original connectmanual telnet step and end after the final ENTER NUMBER TO DIAL keystroke is transmitted. I can also add a few trnsmit ESC commands to bring me back to the original input screen if needed.

proc main
string sLine


; TELNET INTO THE CONTROLLER
connectmanual telnet "89.1.16.105"
; CHOOSE 1 SELECT UNIT
waitfor "SELECT UNIT" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"

; CHOOSE 1 TO CHANGE THE SHELF
waitfor "SHELF=" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
transmit "^M"

; ENTER THE SHELF NUMBER
waitfor "ENTER SHELF : ^[[24;28H" Forever
transmit "3"
transmit "^M"


; CHOOSE 2 TO CHANGE THE SLOT
waitfor "ENTER SELECTION : " Forever
transmit "2"
transmit "^M"

; ENTER THE SLOT NUMBER
waitfor "ENTER SLOT : ^[[24;27H" Forever
if fopen 0 "data.txt" READ TEXT
fgets 0 sLine
transmit sLine
transmit "^M"
endif

; CHOOSE 3 TO ENTER THE SHELF AND SLOT CHOSEN
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "3"
transmit "^M"

; CHOOSE 7 FOR DIAL BACKUP
waitfor "DIAL BACKUP" forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "7"
transmit "^M"

; CHOOSE 1 TO GO TO DIAL BACKUP
waitfor " GO TO DIAL BACKUP" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"

; CHOOSE 1 TO DIAL STORED NUMBER
waitquiet 1
waitfor "DIAL STORED NUMBER" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
transmit "^M"

; CHOOSE 1 TO DIAL THE FIRST STORED NUMBER
waitfor "ENTER NUMBER TO DIAL :" Forever
transmit "1"
transmit "^M"

endproc

HELP ME KNOB, YOUR'RE MY ONLY HOPE!
 
Give this script a try. It opens up data.txt at the beginning (if it can't be opened, then the rest of the script will not execute), then uses fgets at the beginning of the loop. If the string read from data.txt is null, then exitwhile is used to jump out of the while not feof 0 loop and the script completes.

proc main
string sLine

if fopen 0 "data.txt" READ TEXT
; TELNET INTO THE CONTROLLER
connectmanual telnet "89.1.16.105"
while not feof 0
fgets 0 sLine
if nullstr sLine
exitwhile
endif
; CHOOSE 1 SELECT UNIT
waitfor "SELECT UNIT" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"

; CHOOSE 1 TO CHANGE THE SHELF
waitfor "SHELF=" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
transmit "^M"

; ENTER THE SHELF NUMBER
waitfor "ENTER SHELF : ^[[24;28H" Forever
transmit "3"
transmit "^M"


; CHOOSE 2 TO CHANGE THE SLOT
waitfor "ENTER SELECTION : " Forever
transmit "2"
transmit "^M"

; ENTER THE SLOT NUMBER
waitfor "ENTER SLOT : ^[[24;27H" Forever


transmit sLine
transmit "^M"


; CHOOSE 3 TO ENTER THE SHELF AND SLOT CHOSEN
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "3"
transmit "^M"

; CHOOSE 7 FOR DIAL BACKUP
waitfor "DIAL BACKUP" forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "7"
transmit "^M"

; CHOOSE 1 TO GO TO DIAL BACKUP
waitfor " GO TO DIAL BACKUP" Forever
waitfor "ENTER SELECTION : ^[[24;32H" Forever
transmit "1"
transmit "^M"

; CHOOSE 1 TO DIAL STORED NUMBER
waitquiet 1
waitfor "DIAL STORED NUMBER" Forever
waitfor "ENTER SELECTION : ^[[24;32H"
transmit "1"
transmit "^M"

; CHOOSE 1 TO DIAL THE FIRST STORED NUMBER
waitfor "ENTER NUMBER TO DIAL :" Forever
transmit "1"
transmit "^M"
endwhile
endif
fclose 0
endproc


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

Part and Inventory Search

Sponsor

Back
Top