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!

Need help in setting variable for output entered

Status
Not open for further replies.

Ozzietech

Technical User
Jun 1, 2005
29
AU
Hi all
I have a question where i issue a command on a PABX to find out an IP address on a terminal.
I transmit "pingall -s"
the system outputs
Testing..

HostName IPAddress Status
SERVERNAME 192.168.50.241 Pass

I need the IP address to be captured as a string variable (we shall call the string servip) so i can then issue a command
Transmit "telnet "
transmit servip
transmit "^M"


any help would be appreciated.
Cheers
Andy
 
What you could do is use a waitfor "HostName" command to detect the header that is returned for the command, then a couple rget commands (at least two, possibly more depending on the system you are connecting to and how it transmits data) to read the next couple lines of output. To determine how many you need, start with two commands, then use the usermsg command to display the value from the last line read. Increase the number of rget commands if necessary until you have the full string being read successfully.

You could then use the strextract or strtok command to pull out the IP address. Do you know what non-printable characters (spaces, tabs, etc.) are between the hostname and the IP address? That would make a difference on the arguments for the command. If not, you can use Procomm's Monitor Window to get this information (some info pasted below):

Procomm's Monitor Window can be used to view the incoming and outgoing data, in both hex and ASCII format. To activate this window, select the Data | Monitor Window menu item. Resize the Monitor Window so that you can view the entire width of the window, then click back in the Procomm Plus window so that the Monitor Window does not have focus. Incoming text is displayed in red, while text you send is colored blue. The Monitor Window can be handy for viewing incoming escape sequences (to determine if Procomm Plus is responding properly to them) or to verify that the program is sending the data you think it should be.

 
I sorted it out.
Made it capture to a temp file when it issues the pingall - s command.
here is the code

set capture query off
set capture overwrite on
set capture file "IPtemp"
clear
capture on
transmit "pingall -s^m"
waitfor "Pass"
capture off
fopen 0 fname read text
while not feof 0 ; Loop while not end of file.
fgets 0 fline
if strfind fline "Pass"
strread fline 20 servip 16 ; read 16 characters from the 20th character on that line
endif
endwhile
fclose 0
Transmit "telnet "
transmit servip
transmit "^M"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top