新浦京81707con > 注册购买 > SecureCRT中Script脚本使用心得

原标题:SecureCRT中Script脚本使用心得

浏览次数:170 时间:2019-11-20

SecureCRT中Script脚本金和利息用体验

在SecureCRT中利用VBSCLX570IPT脚本,确实能够增加我们的工效,何况能够完成完全的自动化。

SecureCRT给我们提供了很好的阳台——脚本工具创制和平运动行。下边就SecureCRT工具常用到的多少个函数演说如下:

1. 在SecureCRT里,用得最多的相应正是crt.Screen,基本上超级多操作都以依照显示屏的回来字来决定下一步该作何操作:

(1):crt.Screen.WaitForString("KeyString",timewaiting)

该函数是单字符串判别,KeyString是内需搜求的根本字,timewaiting是叁个过期阀值,比方:crt.Screen.WaitForString("people:",5)该行代码的情趣正是在5秒内并没有检查评定到people:现身,就实行下一条语句,倘若改成:crt.Screen.WaitForString("people:")那就是指直到people:现身才奉行下大器晚成行代码。

WaitForString是有重临值的,再次回到值是True 恐怕False。因而,可以依据重返值实行标准化判定以鲜明一下条代码。举个例子:

If (crt.Screen.WaitForString ("current state : UP",1)<>False) Then
portStatus="PortUP"
Else
portStatus="PortDown"
End If

msgbox portStatus

这段代码用于判定端口状态情形并记下下来.

(2):crt.Screen.WaitForStrings("KeyString1","KeyString2",...,timeout)

用于多少个字符串的剖断,timeout的效用是平等的。比方:

crt.Screen.WaitForStrings("cisco","huawei","H3C",5)

意思就是在5秒内有检验到对应的字符时,再次回到相应的索引号(索引号是从1从头的卡塔尔。借使都没有检查到,则赶回0.据此,该函数的利用能够如下:

Dim SwitchKey

SwitchKey=crt.Screen.WaitForStrings("cisco","huawei","H3C",5)

Select case SwitchKey

case 1

MsgBox "Cisco道具"

case 2

MsgBox "Nokia设备"

case 3

MsgBox "华三设备"

case else

Msg博克斯 "未知设备"

End Select

(3) 其实SecureCRT帮忙的脚本语言正是VBS,那几个脚本语言与VB有异常的大的两样,对于分界面的支持性非常差。不过也可能有几个对话性的函数

<1>、InputBox :提示顾客输入参数

temp = inputbox("提示顾客你输入参数的名号","对话框的名号") :要求将输入的参数赋值给某三个参数实行应用。

<2>、输出函数 msgbox

msgbox “给客商输出的音信对话框”

eg.求长方形面积的剧本

dim r,s
r=inputbox("请输入长方形的边长:","求圆柱形面积的前后相继")
s=r*r
msgbox(s)


语句结构:

1. 挨门挨户实施的台本,举个网络泛滥的例子,那几个自动登陆种类的例证,稍加改过如下。

# $language = "VBScript"
# $interface = "1.0"

Sub Main
'连接主机192.168.0.2
crt.session.Connect("/telnet 192.168.0.2")
'等待出现登入客户名提醒login,等待时间是10s
crt.screen.WaitForString "login:",10
'输入客商名,回车
crt.screen.send "minico" & Chr(13)
'等待现身登录密码提醒login,等待时间是10s
crt.screen.WaitForString "Password:",10
'输入密码,回车
crt.screen.send "123456"

crt.screen.send Chr(13)
End Sub

  1. 接收结构的脚本

if ... then ...else...结议和case结构见幼功知识比如

  1. 巡回结构

 

 

 

剧本实例

#=====================================================

# $language = "VBScript"
# $interface = "1.0"
'============================================================================================='
'    程序名称:AIX.VBS
'    程序表明:AIX主机系统布局/巡检脚本
'    作者:郑继东
'    完结时间:2009-5-7
'============================================================================================='

'============================================================================================='
'    程序全局变量区
'============================================================================================='
dim ip

'============================================================================================='
'    程序全局常量区
'============================================================================================='
' button parameter options
Const ICON_STOP = 16                 ' display the ERROR/STOP icon.
Const ICON_QUESTION = 32             ' display the '?' icon
Const ICON_WARN = 48                 ' display a '!' icon.
Const ICON_INFO= 64                  ' displays "info" icon.
Const BUTTON_OK = 0                  ' OK button only
Const BUTTON_CANCEL = 1              ' OK and Cancel buttons
Const BUTTON_ABORTRETRYIGNORE = 2    ' Abort, Retry, and Ignore buttons
Const BUTTON_YESNOCANCEL = 3         ' Yes, No, and Cancel buttons
Const BUTTON_YESNO = 4               ' Yes and No buttons
Const BUTTON_RETRYCANCEL = 5         ' Retry and Cancel buttons
Const DEFBUTTON1 = 0        ' First button is default
Const DEFBUTTON2 = 256      ' Second button is default
Const DEFBUTTON3 = 512      ' Third button is default

' Possible MessageBox() return values
Const IDOK = 1              ' OK button clicked
Const IDCANCEL = 2          ' Cancel button clicked
Const IDABORT = 3           ' Abort button clicked
Const IDRETRY = 4           ' Retry button clicked
Const IDIGNORE = 5          ' Ignore button clicked
Const IDYES = 6             ' Yes button clicked
Const IDNO = 7              ' No button clicked

'============================================================================================='
'    程序救助函数区
'============================================================================================='

'登录函数
Function login
    '定义IP地址,登入顾客名,密码变量
    dim    passwd
    dim username

    Dim result
    Dim flag
    flag =1
    '断开主机连接
    crt.session.Disconnect

    '开启对话框,获得IP地址,登入客户名称,密码等变量
    ip = crt.Dialog.Prompt("请输入服务器IP地址:", "AIX", "192.1.1.207", false)
    If (Trim(ip) = "")  Or (ip = IDABORT) Then
        result = crt.Dialog.MessageBox("您未有输入登入的IP地址,CRT将被分离!", "提醒消息",ICON_INFO)
        crt.quit
    End If

    flag =1
    While flag = 1
        username = crt.Dialog.Prompt("请输入登录客户名:", "AIX", "root", false)
        If     username = IDABORT Then
            result = crt.Dialog.MessageBox("您接受了没有输入客户名称,CRT将被生产!", "提醒消息",ICON_INFO)           
            crt.quit
        End If

        If (Trim(username) = "")Then
            result = crt.Dialog.MessageBox("请输入登入顾客名称!", "提示音讯",ICON_INFO)
        Else
            flag = 0
        End If
    wend

    passwd = crt.Dialog.Prompt("请输入登入用户密码:", "AIX", "congine", true)

    '连接主机
    crt.screen.Synchronous = true
    crt.session.Connect("/telnet " & ip)
    '等待出现登录顾客名提醒login,等待时间是10s
    crt.screen.WaitForString "login:"
    '输入客户名,回车
    crt.screen.send username & chr(13)

    '等待现身登入密码提示login,等待时间是10s
    crt.screen.WaitForString "Password:"
    '输入密码,回车
    crt.screen.send passwd & chr(13)
    If crt.screen.WaitForString("invalid login name or password", 3) = True Then
        result = crt.Dialog.MessageBox("服务器登录战败,请检查IP地址、客户名、密码是或不是输入正确!", "提醒新闻",ICON_INFO)
        crt.quit
    End If
    crt.screen.Synchronous = false
End Function

'记录当前对话日志函数
Function writelog   
    Dim result
    Dim logfilename
    Dim flag
    flag =1

    While flag =1
        logfilename = crt.Dialog.Prompt("请输入此次会话LOG文件地方", "AIX", "c:"  & ip &".log", false)
        If Trim(logfilename) = ""  Or  (logfilename = IDABORT) then
            result = crt.Dialog.MessageBox("刚毅提出保存会话日志", "提醒新闻",ICON_INFO)
        Else
            flag = 0
        End if
    wend
    crt.session.LogFileName = logfilename
    crt.session.Log(true)
End Function

Function  setline
    crt.screen.send chr(13) & chr(13)
'    crt.Sleep 1000
End Function

Function setcommand(cmdstr, sec)
    setline
    sec = sec * 1000
    crt.screen.send cmdstr & Chr(13)
    crt.Sleep sec
End Function

'拿到服务器基本音讯
Function get_machinfo

    '主机基本消息
    setcommand "hostname",1
    setcommand "prtconf |grep 'Machine Serial Number'",6
    '主机设备状态
    setcommand "lsdev -C |grep proc",2
    setcommand "lsattr -El mem0",2
    setcommand "lsdev -Cc disk",2
    setcommand "lsdev -Cc adapter",2
    setcommand "lsdev -Cc tape",2

    '主机网卡景况
    setcommand "ifconfig -a",2
    setcommand "more /etc/hosts",2

    '主机软件新闻
    setcommand "uname -a ",2
    setcommand "oslevel -s",5
    setcommand "instfix -i |grep ML",10

    '主机卷组新闻
    setcommand "lsvg ",2
    setcommand "lsvg -o",2
    setcommand "lsvg -l rootvg",2

    '主机文件系统新闻
    setcommand "df -g ",2

    '主机日志音信
    setcommand "errpt ",2
    setcommand "errpt  -a",2
    setcommand "sysdumpdev -l ",2

    '主机系统质量
    setcommand "lsps -a",2
    setcommand "vmstat 2 10",25
    setcommand "iostat 2 10",25

End Function

'============================================================================================='
'    程序主函数(main卡塔尔国区
'============================================================================================='

'主函数
Sub Main
    Dim result
'    crt.screen.Synchronous = true
    '系统登入
    login

    '写日志
    writelog

    '得到服务器消息
    get_machinfo
    result = crt.Dialog.MessageBox("消息搜罗实现,是不是推出CRT?", "提示新闻", ICON_QUESTION Or BUTTON_YESNO Or DEFBUTTON2)
    If    result = IDYES Then
        crt.quit
    End If

    '甘休会话日志
    crt.session.Log(false)
'    crt.screen.Synchronous = false
End Sub

在SecureCRT中选择VBSCQX56IPT脚本,确实能够巩固大家的工效,並且能够兑现完全的自动化。 SecureCRT给大家提供了...

本文由新浦京81707con发布于注册购买,转载请注明出处:SecureCRT中Script脚本使用心得

关键词: 新浦京81707con

上一篇:jquery滚动条插件jScrollPane的使用介绍,滚动条插件

下一篇:没有了