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

Auto Login Script

Status
Not open for further replies.

cabetcl

Technical User
Mar 21, 2003
3
US
I have created a automated login scripts that logges a user to several Telnet sessions "20" or more.

When the user used to Manualy login to this Telnet sessions he would have to select from several menus until he reached the destination. Example:

01 ) Northeast 02 ) West 03 ) South

Please make your selection >

At this point the user would use the numeric value for its destination. the he would get the next menu:

01 ) NewYork 02 ) New Jersey 03 ) Washington

Please make your selection >

Again the user would use the respective numeric value for its destination.

I had all this setup working using the predefined sequence of numbers.

like:
transmit "01"
waitfor "selection"
transmit "02" ...... and so on. It worked Fine until new network elements were added and it messed up the entire sequence of numbers.

Now I'm trying to create a Smart Script that will analize the terminal screen and search for example "Northeast" and then locate the respective number and then transmit it.

This way if Northeast's respective numeric value is changed the script will always transmit the correct number.

I found "strcspn" command that will compare 2 strings and locate the position where a single character is the same.

Is there a way to compare 2 string and locate the position where an entire word is the same?

Any help is appreciated

Thanks

Claudio

 
You could use locate to postion your cursor at different points of the screen and termreads to store screen info for processing. The example below reads all lines of a 80x24 terminal screen.

Code:
proc main
string readline                    ;String to read line
integer rownum, colnum             ;Row and column position
integer row                        ;Integer for current row

getcur rownum colnum               ;Get cursor position
for row = 0 upto 23                ;Loop for 24 Lines 
   locate row 0                    ;Place cursor on row
   termreads readline 80           ;Read 80 Characters
   if strfind readline "Northeast" ;Process the line   
                                   ;
   elseif strfind readline "West"  ;
                                   ;
   elseif strfind readline "South" ;
                                   ;
   endif                           ;
endfor                             ;End loop
locate rownum colnum               ;Respositon cursor
                                   ;Continue processing
endproc
 
A slightly modified version that may work for you but that really depends what the screen displays.

Code:
proc main
string readline,selected,sitename
integer rownum,colnum,row,sel                   
sitename = "Northeast"            ;Northeast selected
getcur rownum colnum               
for row = 0 upto 23                
   locate row 0                    
   termreads readline 80           
   if strfind readline sitename    
      atoi sitename sel           ;Change line to integer
      strfmt selected "%02d" sel  ;2 digit format ie. 1=01
      exitfor                     ;exit loop
   endif
endfor                             
locate rownum colnum               
transmit selected                 ;transmit selection
transmit "^M"                     ;transmit enter key
endproc
 
The above example assumes each site is on a diffent line. This example is for all sites on a single line seperated by " ) " as your example shows above.

Code:
proc main
string readline,selected,sitename,slct
integer rownum,colnum,row,sel,count,len
sitename = "Northeast"
getcur rownum colnum               
for row = 0 upto 23                
   locate row 0                    
   termreads readline 80           
   if strfind readline sitename    
      strreplace readline " ) " ","
      strlen sitename len
      strfind readline "," sel
      for count = 0 upto sel+1
         strextract slct readline "," sel+1
         substr slct slct 0 len
         if strcmp slct sitename
            strextract selected readline "," sel
            atoi selected len
            strfmt selected "%02d" len
            exitfor
         endif
      endfor
      atoi sitename sel
      strfmt selected "%02d" sel
      exitfor
   endif
endfor                             
locate rownum colnum               
transmit selected
transmit "^M"
endproc
 
mrnoisy .. Thank you very much. it works just fine.

I do have another question.

is it possible to call a especific procedure on a script that has a lot of procedures?
 
You cannot call a specific procedure from a script. However, if you have a handy procedure or function you would like to use in multiple scripts, you can place that procedure in a .inc file. Then, add the .inc file as an include in your script file.

For instance, to run a procedure called CleanUp from a .inc file called common.inc (which resides in the same directory as your script), your script file would look like the following.

Code:
#include "common.inc"

proc main
;
;
CleanUp()
;
;
endproc
 
Hi mrnoisy. thanks again.

with your help I was able to make my script work,

here is the modified sample:

string eselect = "Network Element Selection by Area"
string area = "Northeast"
string state = "New York"
string msc = "Laight Street"
string vendor = "Lucent"
string netype = "OMP"
string element = "LaightSt-OMP"
string readline,selected
integer row,Pos

proc main

call eselect_

endproc

; #################################################################

proc eselect_

for row = 0 upto 23
locate row 0
termreads readline 80
if strfind readline eselect Pos
Pos = Pos - 5
;usermsg readline
strread readline Pos selected 2
;usermsg selected
transmit selected ;transmit selection
transmit "^M" ;transmit enter key
endif
endfor
pause 1
call area_
endproc

; #################################################################

proc area_

for row = 0 upto 23
locate row 0
termreads readline 80
if strfind readline area Pos
Pos = Pos - 5
;usermsg readline
strread readline Pos selected 2
;usermsg selected
transmit selected ;transmit selection
transmit "^M" ;transmit enter key
endif
endfor
pause 1
call state_
endproc

; #################################################################

proc state_

for row = 0 upto 23
locate row 0
termreads readline 80
if strfind readline state Pos
Pos = Pos - 5
;usermsg readline
strread readline Pos selected 2
;usermsg selected
transmit selected ;transmit selection
transmit "^M"
endif
endfor
pause 1
call msc_
endproc

; #################################################################

proc msc_

for row = 0 upto 23
locate row 0
termreads readline 80
if strfind readline msc Pos
Pos = Pos - 5
;usermsg readline
strread readline Pos selected 2
;usermsg selected
transmit selected ;transmit selection
transmit "^M"
endif
endfor
pause 1
call vendor_
endproc

; #################################################################

proc vendor_

for row = 0 upto 23
locate row 0
termreads readline 80
if strfind readline vendor Pos
Pos = Pos - 5
;usermsg readline
strread readline Pos selected 2
;usermsg selected
transmit selected ;transmit selection
transmit "^M"
endif
endfor
pause 1
call netype_
endproc

; #################################################################

proc netype_

for row = 0 upto 23
locate row 0
termreads readline 80
if strfind readline netype Pos
Pos = Pos - 5
;usermsg readline
strread readline Pos selected 2
;usermsg selected
transmit selected ;transmit selection
transmit "^M"
endif
endfor
pause 1
call element_
endproc

; #################################################################

proc element_

for row = 0 upto 23
locate row 0
termreads readline 80
if strfind readline element Pos
Pos = Pos - 5
;usermsg readline
strread readline Pos selected 2
;usermsg selected
transmit selected ;transmit selection
transmit "^M"
endif
endfor
pause 1

endproc


Once again Thank You
 
I noticed that all of your procedures are the same. You could simplify your script by creating one procedure using param for your string variable.

Code:
string readline,selected
integer row,Pos

proc main
SelectOption("Network Element Selection by Area")
SelectOption("Northeast")
SelectOption("New York")
SelectOption("Laight Street")
SelectOption("Lucent")
SelectOption("OMP")
SelectOption("LaightSt-OMP")
endproc

proc SelectOption
param string strvalue
for row = 0 upto 23
   locate row 0                    
   termreads readline 80           
   if strfind readline strvalue Pos 
      Pos = Pos - 5
      strread readline Pos selected 2   
      transmit selected
      transmit "^M"
   endif
endfor
pause 1
endproc


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top