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

Copying text from screen and reusing it

Status
Not open for further replies.

Isriam

Technical User
Sep 2, 2004
10
US
Hi, I'm just learning aspect and I'm having a hard time completing my script.

I want to copy text from the screen and use it later in a transmit command.

The systems that I am working on have a system name like (0114.008.01) SID#21>

Each system has a different name, and different length. I'd like to extract this, and use it later to download a database file and name it as the system name. Here is a copy of my script. I am manually entering in system names instead of grabbing the name thats output by the system.

proc main
string tftp
sdlginput "TFTP Server" "Enter TFTP Address" tftp
strcat tftp " "
pause 3
Connect telnet GROUP "SD NAV"
waitfor "^M^J"
transmit "^M"
waitfor " Login: "
transmit "*****^M"
waitfor " Password: "
transmit "******^M"
waitfor "> "
transmit "upload tftp config "
transmit tftp
transmit " "
call Nav1
transmit "^M"
waitfor "> "
transmit "exit^M"
endproc

proc Nav1
integer iDay, iMonth, iYear, iHour, iMin, iSec
string sFileName
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt sFilename "`"SD_Nav1_%d-%d`"" iMonth iYear
transmit sFilename
endproc

Instead of SD_NAV1 I'd like this to be the actual system name taken from the > prompt. Each system has a system name then > as a prompt. Here is a copy paste from the system once I'm logged in:

Carrier Access - Access Navigator

03:29:36 09/02/2004

Login: *******
Password: ********

(0114.008.01) SID#21> upload tftp config 4 "SD_Nav1_9-2004"
*-------------------------------------------^

(0114.008.01) SID#21>

Any help would be GREATLY appreciated. I've read over many pages here and found some things to do close to what I want, however I can't get them to work like I need since each system I log into has a different name.
 
What is considered the name of the system above? (0114.008.01) SID#21 or just a portion of the string? If you are looking for the whole string, here is a script that will show you how to get the whole prompt (minus the >) into a string for further use:

proc main
string sPrompt, sTemp
integer iPos

termgets $ROW 0 sTemp
strfind sTemp ">" iPos
substr sPrompt sTemp 0 iPos
usermsg "%s" sPrompt
endproc

If this works for you, then you would want to copy the above code (minus the usermsg command) after the first waitfor "> " in your script.

aspect@aspectscripting.com
 
Man that was awesome! Exactly what I needed. Could you explain what the command was that extracted everything up to the > key? I'd like to be able to do this for things such as alarm reports and whatnot.

I'm currently testing my script, I'll post it when I'm finished for review if anyone ever works on Carrie Access Navigators.

Also does the Connect GROUP function work? I can't seem to get it to call my group in order. Doesn't it connect to the next dial entry when terminal sees no carrier detect?
 
Here is my finished script. I have around 100 of these to do, so you can see why I'd like to call a group instead of typing in each system name for CONNECT. Or maybe a Loop would work? I'm copy pasting this like 100 times from the Connect portion.

proc main
integer iDay, iMonth, iYear, iHour, iMin, iSec, iPos
string sNav
string sTftp
string sPrompt, sTemp
sdlginput "TFTP Server" "Enter TFTP Address" sTftp
strcat sTftp " `""
pause 3
Connect telnet GROUP "SD NAV"
waitfor "^M^J"
transmit "^M"
waitfor " Login: "
transmit "*******^M"
waitfor " Password: "
transmit "*******^M"
waitfor "> "
termgets $ROW 0 sTemp
strfind sTemp ">" iPos
substr sPrompt sTemp 0 iPos
transmit "upload tftp config "
transmit sTftp
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt sNav "_%d-%d`"" iMonth iYear
transmit sPrompt
transmit sNav
transmit "^M"
waitfor "> "
transmit "exit^M"
pause 3
endproc
 
I use the strfind command to locate where the > is in the string (this gets stored in the integer variable iPos). I then use the substr command and tell it to copy everything upto but not including the character at the iPos location into the second string.

What you need to do to connect to all entries is use the CONNECTALL flag in the dial command. However, this does not work for telnet connections. However again, I have a sample script that goes through all telnet entries in the Connection Directory and connects to all of them. Here is a framework that you can put into your script:

proc main
integer iEntries ;Number of entries in dialing class
integer iCount ;Loop variable
string sName ;Name of Connection Directory entry

dialcount TELNET iEntries ;Get number of entries in specified dialclass
for iCount = 0 upto (iEntries - 1)
dialname TELNET iCount sName ;Get entry name corresponding to index number
statmsg sName
dial TELNET sName ;Make telnet connection
while $DIALING ;Loop while making connection
yield
endwhile
pause 1
if $CARRIER == 1 ;If connected
;do commands here
endif
endfor
endproc

aspect@aspectscripting.com
 
Awesome, thank you. I will add this and let you know how I get it worked out. Thanks for the help, I know little to no programming and have been pouring over the Aspect help in procomm to build what I have so far. Been fun!
 
So is this dial issue a problem in procomm? The thing is, I have a lot of telnet connections. I don't want to connect to all of them, just certain ones at certain times. I've gone over it in my head a few times and its becoming complicated. I was playing with the dialog box script on your website, but I can't get it to let me select multiple connections at once.
 
If you change the dialcount and dialname commands in the example I posted to read this:

dialcount TELNET GROUP "test" iEntries

and

dialname TELNET GROUP "test" iCount sName

then all entries in the group named "test" will be dialed. Hopefully that helps you out, just remember that the group name is case-sensitive.


aspect@aspectscripting.com
 
Thank you for your help! This worked perfectly after a few tweaks.

I have another quick question. I've been playing around all morning and I can't seem to get this to work. I have another string that I need to strip things out of, however the string can be two different things. Either A:Active or B:Active. I can get A:Active to get removed but I can't add both to be removed.

termgets $ROW 0 sTemp
strfind sTemp " (B:Active) > " iPos
substr sPrompt sTemp 0 iPos

this removes the B:Active but what if Row 0 has A:Active instead of B:Active?

I hope that makes sense :/ Basically its a command prompt that changes depending on which CPU is active.
 
Maybe I figured it out myself, this worked great. Let me know if you have any comments on what I should maybe change.

proc main
integer iDay, iMonth, iYear, iHour, iMin, iSec, iEntries, iCount
string sWB, sName, sTftp, sPrompt, sTemp
sdlginput "TFTP Server" "Enter TFTP Address" sTftp
strcat sTftp " `""
dialcount TELNET GROUP "LA WB" iEntries
for iCount = 0 upto (iEntries - 1)
dialname TELNET GROUP "LA WB" iCount sName
statmsg sName
dial TELNET sName
while $DIALING
yield
endwhile
pause 1
set capture file "Widebank.txt"
capture on
if $CARRIER == 1
Pause 2
transmit "*******^M"
waitfor " Password: "
transmit "********^M"
waitfor "> "
termgets $ROW 0 sTemp
substr sPrompt sTemp 0 9
transmit "save tftp "
transmit sTftp
ltimeints $LTIME iYear iMonth iDay iHour iMin iSec
strfmt sWB "_%d-%d-%d`"" iMonth iDay iYear
transmit sPrompt
transmit sWB
transmit "^M"
waitfor "> "
transmit "exit^M"
endif
endfor
capture off
endproc
 
Actually now that I'm thinking about it, I'm not happy with that setup. Is there anyway I can remove this string in either format instead of how I'm using character place #'s above?

309-14-03 (B:Active) >
309-14-03 (A:Active) >

Row 0 can be either of the above two formats. If I substr using substr sPrompt sTemp 0 9 and my place numbers are off 1 digit, I might delete a number I need. I just need to remove the (A:Active) > part. :)
 
Are you basically needing everything before the first space character? If so, you could use the strextract command to pull all data from before the first space. You would need to change this line:

substr sPrompt sTemp 0 iPos

to read:

strextract sPrompt sTemp " " 0


aspect@aspectscripting.com
 
thank you i'll play with that command awhile :)
 
i would recommend having 1 script, and a flat text file with a hundred ip addresses on it .... this is sort of a crude example i know but i am not at my regular pc. but i i used to use a variation to shove in 2-3000 telephone numbers in a sitting, so would recommend it for ip addresses as well.

proc main
strings defined

sdlgfopen "TRY" "C\*.*" SINGLE TEST
fopen 1 TEST READ TEXT

TRANSMIT "wakeup"
WAITFOR "reply" 60

FEOF 1 EOF
WHILE !EOF
FGETS 1 NUM1
FEOF 1 EOF
STRCMP NUM1 "" RESULT
IF RESULT != 0
STRFMT ipNUMADD "your commands here" NUM1
TRANSMIT ipNUMADD
WAITFOR "reply" FOREVER
ENDIF
endwhile
endproc

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top