VanDyke Software Forums

Go Back   VanDyke Software Forums > Scripting
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-03-2012, 02:14 PM
mr_dre2u mr_dre2u is offline
Registered User
 
Join Date: May 2012
Posts: 2
Problem with running script with Telnet

when running the following script the script sometimes skips ip's. Using connectInTab method instead of connect I realised that it was executing the next iteration of the for-loop before the previous one completed for some items. Why is that?


Sub Main

On Error Resume Next

Dim response
Dim ips
Dim ip
Dim count
set count=0
Dim test
'Array of IPM IPs
ips= array("10.227.44.37","10.227.44.40","10.227.44.41")

'Array of IPM Names
area=array("Arnos1","Arnos2","Arnos3")

'user input prompt
Dim strUserInput
strUserInput = InputBox( "Enter the current month and year separated by a '.' Example: 'Mar.2012'" )
'crt.Screen.Synchronous = True
'Driver. Iterates through all the IPs in the ips array
for each ip in ips
crt.Session.Connect "/TELNET " + ip 'Creates telnet connection
Saver(area(count))
crt.Screen.Send count
'BackUp area(count), strUserInput
count= count+1

next
End Sub

'performs save action
Sub Saver(strMSAN)
crt.Screen.WaitForString ">>User name:"
crt.Screen.Send "root" & chr(13)
crt.Screen.WaitForString ">>User password:"
crt.Screen.Send "admin" & chr(13)
crt.Screen.WaitForString(strMSAN+">")
crt.Screen.Send "en" & chr(13)
crt.Screen.WaitForString(strMSAN+"#")
crt.Screen.Send "con" & chr(13)
crt.Screen.WaitForString(strMSAN+"(config)#")
crt.Screen.Send "save" & chr(13)
response=crt.Screen.WaitForStrings (chr(123)+" <cr>" & chr(124) & "configuration<K>" & chr(124) & "data<K> " & chr(125) & ":" , strMSAN+"(config)#")

If response = 1 Then
crt.Screen.Send "configuration" & chr(13)
crt.Screen.WaitForString( "uplicate complete")
End If


End Sub

'performs back-up action
Sub BackUp(strMSAN, strUserInput)
crt.Screen.Send ("backup configuration tftp 172.20.224.139 config_"+strMSAN+"."+strUserInput+".txt" & chr(13))
crt.Sleep 100
crt.Screen.WaitForString(strMSAN+"(config)#")
crt.Screen.Send "quit" & chr(13)
crt.Screen.WaitForString(strMSAN+"#")
crt.Screen.Send "quit" & chr(13)
crt.Screen.WaitForString "Are you sure to log out? (y/n)[n]:"
crt.Screen.Send "y" & chr(13)

End Sub
Reply With Quote
  #2  
Old 05-03-2012, 02:53 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Greetings,

Do you get better results if you uncomment 'crt.Screen.Synchronous = True?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 05-04-2012, 05:24 AM
mr_dre2u mr_dre2u is offline
Registered User
 
Join Date: May 2012
Posts: 2
no. Same results
Reply With Quote
  #4  
Old 05-04-2012, 08:26 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
You're using crt.Session.Connect, and no crt.Session.Disconnect. I think the session must be getting closed in a way that's not obvious in the code, because you would probably see an error if trying to use Connect when already connected. So, I think there's more going on than has been shown.

Are you disconnecting from the remote through some other command before trying again to connect?

When you say it's skipping IP's, how are you making that determination?

Which version of SecureCRT are you using (Help / About SecureCRT...)?

Can you add a msgbox do you see that IP's are not skipped, and see if you notice anything different about the SecureCRT connections?
Code:
for each ip in ips
  crt.Session.Connect "/TELNET " + ip 'Creates telnet connection
  Saver(area(count))
  crt.Screen.Send count
  'BackUp area(count), strUserInput
  count= count+1

  ' Debug MsgBox to help verify that no IP addresses are skipped
  MsgBox "IP = " & ip & vbcr & "count = " & count   
next
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
Reply

Tags
connect, telnet


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:32 AM.


copyright 1995-2014 VanDyke Software, Inc.