http://www.justwinit.cn/post/2295/
每次都要去chmod -R * ;chown -R nobody.nogroup * 很是麻烦,写一脚本解决,到时候直接调用一下secureCRT的脚本--》运行--》选择脚本即可!
代码如下:
Sub Main
crt.Screen.Synchronous = True
crt.Screen.Send "chmod -R 755 *" & vbcr
crt.Screen.Send "chown -R nobody.nogroup *" & vbcr
crt.Screen.Send " "
crt.Screen.Synchronous = False
End Sub
【前言】
SecureCRT是一款非常流行和受欢迎的远程登录和终端仿真软件,支持Telnet,SSH等。
它还可以支持VBScript和JScript,通过Script的支持,SecureCRT能够自动完成我们设定
好的各种任务。
【示例一】
# $language = "VBScript"
# $interface = "1.0"
'本脚本示范:自动登录到某台3550交换机设备,自动输入远程登录密码,同时自动进入特权模式
'自动输入特权密码,同时运行show version命令
Sub Main
crt.Screen.Synchronous = True
'通过telnet连接到192.168.1.1
crt.Session.Connect "/TELNET 192.168.1.1"
crt.Screen.WaitForString "Password:"
crt.Screen.Send "cisco" & vbCr
crt.Screen.waitForString ">"
crt.Screen.Send "enable" & vbcr
crt.Screen.WaitForString "Password:"
crt.Screen.Send "cisco" & vbcr
crt.Screen.waitForString "#"
crt.Screen.Send "show version" & vbcr
crt.Screen.waitForString "--More--"
crt.Screen.Send " "
crt.Screen.Synchronous = False
End Sub
【示例二】
# $language = "VBScript"
# $interface = "1.0"
'本脚本示范:从一个文件里面自动读取设备IP地址,密码等,自动将设备配置备份
Sub Main
'打开保存设备管理地址以及密码的文件
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso,file1,line,str1,params
Set fso = CreateObject("Scripting.FileSystemObject")
Set file1 = fso.OpenTextFile("d:\config.txt",Forreading, False)
crt.Screen.Synchronous = True
DO While file1.AtEndOfStream <> True
'读出每行
line = file1.ReadLine
'分离每行的参数 IP地址 密码 En密码
params = Split (line)
'Telnet到这个设备上
crt.Session.Connect "/TELNET " & params(0)
'输入telnet密码
crt.Screen.WaitForString "Password:"
crt.Screen.Send params(1) & vbcr
'进特权模式
crt.Screen.Send "enable" & vbcr
crt.Screen.WaitForString "Password:"
crt.Screen.Send params(2) & vbcr
crt.Screen.waitForString "#"
'备份目前Startup配置
str1 = "copy startup tftp://192.168.1.2/"
str1 = str1 & "backup(" & params(0) &")" & ".cfg"
crt.Screen.Send str1 & vbcr
crt.Screen.WaitForString "]?"
crt.Screen.Send vbcr
crt.Screen.WaitForString "]?"
crt.Screen.Send vbcr
'备份完成后退出
crt.Screen.waitForString "#",3
crt.Session.Disconnect
loop
crt.Screen.Synchronous = False
End Sub
config.txt文本文件为事先编辑好的
格式如:
192.168.1.1 cisco cisco
192.168.1.254 cisco cisco
前面是IP地址,后面是telnet密码,最后是enable密码
Sub Main
'打开保存设备管理地址以及密码的文件
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso,file1,line,str1,params
Set fso = CreateObject("Scripting.FileSystemObject")
Set file1 = fso.OpenTextFile("d:\config.txt",Forreading, False)
crt.Screen.Synchronous = True
DO While file1.AtEndOfStream <> True
'读出每行
line = file1.ReadLine
'分离每行的参数 IP地址 密码 En密码
params = Split (line)
'Telnet到这个设备上
crt.Session.Connect "/TELNET " & params(0)
'输入telnet密码
crt.Screen.WaitForString "Password:"
crt.Screen.Send params(1) & vbcr
'进特权模式
crt.Screen.Send "enable" & vbcr
crt.Screen.WaitForString "Password:"
crt.Screen.Send params(2) & vbcr
crt.Screen.waitForString "#"
'备份目前Startup配置
str1 = "copy startup tftp://192.168.1.2/"
str1 = str1 & "backup(" & params(0) &")" & ".cfg"
crt.Screen.Send str1 & vbcr
crt.Screen.WaitForString "]?"
crt.Screen.Send vbcr
crt.Screen.WaitForString "]?"
crt.Screen.Send vbcr
'备份完成后退出
crt.Screen.waitForString "#",3
crt.Session.Disconnect
loop
crt.Screen.Synchronous = False
End Sub