SecureCRT Script 学习笔记

来源:互联网 发布:美发会员收银软件 编辑:程序博客网 时间:2024/06/07 01:06
SecureCRT支持ActiveX script engines,包括VBScript和JScript (Microsoft’s version of JavaScript)两种脚本。

Note:如果你想使用脚本自动运行方式的话,需要在session option中进行设置。

脚本可以用任何文本编辑器来开发。Script头部用来识别脚本语言和SecureCRT脚本接口的版本,脚本头部的每一行必须以#开头,头部包括$language行和$interface行。例如,下面是一个简单的脚本。
# $language = "VBScript"
# $interface 
= "1.0"

Sub Main
  
' Display SecureCRT's version
  MsgBox "SecureCRT version is: " & crt.Version
End Sub

代码通常放在main子过程,引擎在执行main子过程前,将转换并执行全局代码(脚本代码定义在任何子过程之外),如果你有一些初始化处理的话,可以使用这一特性。

如果想终止main过程,用VBScript的话,可以用Exit Sub语句。如:

Sub Main

  condition 
= DoSomething()
  
If condition = 0 Then
    
' Error, bailout
    Exit Sub
  
End If
   
End Sub

SecureCRT有一些内建的对象,可以通过顶级应用对象或子对象调用。这些对象都有一些属性和方法。例如:

Dim dlg
Set dlg = crt.Dialog
dlg.Prompt(
"Login:")


下面分享给大家一个脚本:

#$language = "VBScript"#$interface = "1.0"    Sub Main    Dim Counter        crt.Screen.Send "setenv loadaddr 800000" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv fdtaddr 780000" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv bootfile uImage" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv fdtfile mpc8349emitx.dtb" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv serverip 10.1.0.77" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv rootpath /home/test/nfs/rootfs" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv ipaddr 10.1.0.100" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv bootargs root=/dev/nfs mem=1024M rw nfsroot=$serverip:$rootpath ip=$ipaddr:$serverip:$gatewayip:$netmask:$hostname:$netdev:off console=$console,$baudrate $otherbootargs" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv nfsboot 'tftp $fdtaddr $fdtfile\;tftp $loadaddr $bootfile\;bootm $loadaddr - $fdtaddr'" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "setenv bootcmd $nfsboot" & vbCr        crt.Screen.WaitForString "HD-Mother>"        crt.Screen.Send "boot" & vbCr    End Sub