IXPUB技术社区's Archiver

kiki_cinderella 发表于 2008-5-7 15:32

写了一个CRT脚本,用于收集AIX操作系统信息。

下面附件后,解压缩即可看到该脚本。

利用SecureCRT工具,“脚本->运行”选择该脚步,即可运行。

[[i] 本帖最后由 kiki_cinderella 于 2008-5-7 15:37 编辑 [/i]]

kiki_cinderella 发表于 2008-5-7 15:38

附件好像下不来,干脆贴源代码吧。

# $language = "VBScript"
# $interface = "1.0"
'============================================================================================='
'        程序名称:AIX.VBS
'        程序说明:AIX主机系统配置/巡检脚本
'        作者:郑继东
'        完成时间:2008-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

yinheng8066 发表于 2008-5-7 16:07

顶下,谢谢楼主

ytmoo_sky 发表于 2008-5-8 02:26

谢谢楼主哦!^_^

guangdongcandy 发表于 2008-5-10 23:44

楼主能不能把CRT软件共享一下?

czljliu 发表于 2008-7-23 12:58

汗啊  不能下。。

freecxr 发表于 2008-7-24 14:38

好东西 ,高手!崇拜你!顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶

freecxr 发表于 2008-7-24 14:39

回复 5 楼 guangdongcandy的帖子

CRT可以在网上下到破解版的!SecureCRT

wlddd 发表于 2008-8-22 10:14

感谢楼主

a123-456789 发表于 2008-9-23 22:24

Thank you for sharing!

luowenhai 发表于 2008-11-1 10:10

楼主好人

aizhiqiu 发表于 2008-11-7 13:37

真是不错,这样方便多了~:heng:

xy58176913 发表于 2008-11-20 14:59

顶顶顶顶顶顶顶顶顶顶:wuyu:

slightfly 发表于 2009-1-13 16:38

麻烦问一下能不能用脚本实现crt对命令行的阻断功能?多谢

xiaozengxiao 发表于 2009-1-13 21:51

楼主真是太强了。非常非常非常的谢谢。。。有这个东西太方便了。

不过,研究了下,准备在里面加些命令,不知道楼主会不会在意。。

youthenweb 发表于 2009-1-19 10:16

你好
真是太好了,谢谢楼主

zmx_kaiqi 发表于 2009-2-1 13:56

多谢楼主,看看参考。

hangjia 发表于 2009-2-17 14:00

試一下先。

cynthiajinan 发表于 2009-2-24 11:24

有问题想请教楼主,能否提供下邮箱?

bianyu 发表于 2009-4-22 13:12

hao hao ahaohoahahhaha

ramon725 发表于 2009-5-19 10:51

好东西。非常感谢~~~

kakoyu 发表于 2009-6-11 08:59

谢谢,先下来看看,学习了

dkspy 发表于 2009-7-13 09:21

非要用crt软件才行?

cloudinsea 发表于 2009-7-16 16:53

好东东,谢谢分享!

feizhu8888 发表于 2009-7-20 09:42

非常感谢,好好学习,楼主心苦了!

feizhu8888 发表于 2009-7-20 09:46

谢谢,怎么下载不了?

feizhu8888 发表于 2009-7-20 09:51

谢谢楼主,辛苦了,好好学习!

feizhu8888 发表于 2009-7-20 09:52

能够写一下,如何使用吗,好像用不了!

wgjwillis 发表于 2009-7-23 13:21

感谢楼主,马上试用~

friendfan1268 发表于 2009-9-10 17:12

很想学习一下,怎么下不下来呢?

页: [1] 2
IT嘎嘎有奖问题,可兑换实物礼品

Powered by IXPUB技术社区