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

autorun system commands program

Status
Not open for further replies.

peterd51

Technical User
Feb 22, 2005
109
GB
Hi,

I wasn't sure what to make the title say...

I've seen a program called 'Expect' that runs on unix.

Putting it simply, you give it a script and it follows your instructions, calling a program and waiting for the response, then acting on the response. I'm unsure of the exact structure of Expect but what I'd like to do in VB is along the lines of...

For example, to telnet to router:
send 'telnet a.b.c.d'; expect 'username'; else fail
send 'dalton'; expect 'password'; else fail
send 'xyz'; expect 'Signon successful.'; else fail
send 'show version'; expect... etc

Does anyone know of a VB code that will do this? There's no point in re-inventing the wheel!

If not, does anyone have any ideas how I could start to write it?

I've used shell commands in the distant past and I guess there's a better way now but my main concern is getting the responses back into my code...

any ideas on this part of it please?

Regards
Peter

 
This is the bare bones of a programme I wrote several years ago. The full code Telnet's to a number of remote video servers to sync the time and date.

Hopefully this will get you started and you should be able to piece something together from this. A word of warning, this doesn't work with later versions of Telnet. I use version 5.

This is extracted from the connection routine...
ReturnValue = Shell(App.Path & "\TELNET " + IP(i), 1)
AppActivate ReturnValue
Timer2.value = 1200
Timer2.enabled = True

After connecting to the server, start a timer routine to provide an appropriate delay between each sendkeys...

Private Sub Timer1_Timer()
Me.Caption = "Connected to " & IP(i)

Counter = Counter + 1

If Counter <= 1 Then
AppActivate ReturnValue
SendKeys txtUserName + Chr(13), True
End If

If Counter > 1 And Not D1 Then
AppActivate ReturnValue
SendKeys txtPassword + Chr(13), True
D1 = True
End If

If Counter >= 4 And Not D2 Then
AppActivate ReturnValue
SendKeys Chr(27) + "M\Time" + Chr(13), True
D2 = True
End If

If Counter >= 6 And Not D3 Then
AppActivate ReturnValue
SendKeys "Version" + Chr(13), True
D3 = True
End If

If Counter >= 11 And Not D7 Then
AppActivate ReturnValue
If opt_ResetTime.Value = True Then
SendKeys "RESET" + Chr(13), True
Else: SendKeys "Quit" + Chr(13), True
End If
End If

End Sub

If I was doing this again I would probably handle it more efficiently but as they say "If it aint broke..."

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Hi,

Thanks for the input!

Sorry for the delay in responding...I've been off work for a few days.

Regards
Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top