查看SecureCRT帮助文档:

Help-> Help Topics->Scripting -> Script Objects Reference -> Session Object

#$language = "VBScript"
#$interface = "1.0" crt.Screen.Synchronous = True ' This automatically generated script may need to be
' edited in order to work correctly. Sub Main
for i = to
crt.Session.Disconnect
crt.Session.Connect("/TELNET 192.168.1.1")
crt.Screen.WaitForString "login:"
crt.Screen.Send "root" & chr()
crt.Screen.WaitForString "Password:"
crt.Screen.Send "" & chr()
crt.Screen.WaitForString "root@server:"
crt.Screen.Send "df" & chr()
crt.Screen.WaitForString "root@server:"
crt.sleep
next
End Sub

上述脚本也可以把登陆部分放在for循环外面,只是在一台机器上反复执行一条命令隔1秒.

#$language = "VBScript"
#$interface = "1.0" crt.Screen.Synchronous = True ' This automatically generated script may need to be
' edited in order to work correctly. Sub Main
Dim i
i =
Do While i >
crt.Screen.Send "df" & chr()
crt.Screen.WaitForString "root@server:"
crt.Screen.Send "echo ok" & chr()
crt.Screen.WaitForString "root@server:"
crt.Sleep
i=i-
Loop
End Sub

提示符root@ubuntu:~#,可以写成crt.Screen.WaitForString "root@ubuntu:" 
crt.sleep 1000  'sleep 1 seconds

也可以自己录制一个脚本:Script-> Start Recording Script,停止,保存,运行即可。

CRT也支持Python,更加灵活。

05-15 05:08