1. Secure CRT安装
https://www.jb51.net/softs/571793.html
2. 透过SSH连接VM虚拟机
3. CRT发送命令到多个session
View,选择Command Window
在命令上输入窗口<最下面的命令输入框,默认为“Send commands to active session”>, 右键/Send commands to/All Sessions 设置为同时向所有打开的窗口发送给命令
测试,发现,输入一条命令,两个打开的会话均收到该命令。
4. CRT加载配色方案
https://blog.csdn.net/Felix_CB/article/details/85274497
5. Auto log file
正常记录log session,需要停留在打开的session界面,点File/Log Session,另存log的路径,及重命名log文件。
如果实现一打开session,自动记录log,文件名为固定的hostname+年月日
Sessiong/右键/Property
按照如下设置log文件的路径/log名等信息,点击OK
关掉现有Sessiong,重新打开
这样就会按照指定要求开始执行。
此处Session名为IP,可以点Session,右键,即可修改Session的名称。
此处是对单一Session的设定,如果要一次设置,对所有Session有效,则Options---Global Options---Edit Default Settings
6. Secure CRT command loop period/循环时间
如何写一个脚本,按照指定时间间隔不断循环?
#$language = "VBScript"
#$interface = "1.0"
' This automatically generated script may need to be
' edited in order to work correctly.
sleeptime = 2000
' 定义等待时间为2000ms
Sub Main
Do
crt.Screen.Send "ls" & vbCr
crt.Sleep sleeptime
Loop
'执行这些命令后,停止,然后继续执行
End Sub
#$language = "VBScript"
#$interface = "1.0"
' This automatically generated script may need to be
' edited in order to work correctly.
sleeptime = 2000
' 定义等待时间为2000ms
Sub Main
Do
crt.Screen.Send "ls" & vbCr
' & vbCr 为回车键
crt.Sleep sleeptime
Loop Until crt.Screen.WaitForKey(1)
' 循环,直到输入1
End Sub
做一个按键:右键点击下边框---右键---New Button
SendString 用于输入用户名/密码等字符串,此处用于做一个自动调用脚本的button,选择Run Script,指定路径,设定Label为Loop_Demo,颜色为蓝色
设置好后,点击最下面的蓝色圆形按钮,则在目前打开的Session就会自动调用脚本。
7. 多Session
可以根据不同的项目在Session下面建立不同的文件夹,每个Session都可copy,搬移到任意文件夹,方便操作
8. Secure CRT信息采集
#$language = "VBScript"
#$interface = "1.0"
' This automatically generated script may need to be
' edited in order to work correctly.
sleeptime = 2000
' 定义等待时间为2000ms
Sub Main
crt.Screen.Send "ls" & vbcr
crt.Screen.WaitForString "#"
crt.Screen.Send "ifconfig -a" & vbcr
crt.Screen.WaitForString "#"
End Sub
9. Secure CRT run script on all tabs
之前的做法,是每打开一个session,单个执行这些session,如何批量执行所有打开的session?
给所有的tab做一个变量,然后在所有的变量里面做循环。
#$language = "VBScript"
#$interface = "1.0"
' Example script showing how to send commands to multiple tabs
Sub Main
Dim tab, index, nTabCount
nTabCount = crt.GetTabCount()
for index = 1 to nTabCount
set tab = crt.GetTab(index)
tab.activate
tab.Screen.Send "ls" & vbcr
tab.Screen.WaitForString "#"
tab.Screen.Send "ifconfig -a" & vbcr
tab.Screen.WaitForString "#"
crt.sleep 2000
next
End Sub
10. Secure CRT tab different color setting
11. Secure CRT tab different color setting
如果想让每一行log里面显示时间戳:选中session/session options
在On each line 那一框,加入 “%Y-%M-%D_%h:%m:%s” 即可
12. 更改连接属性
此时,还有一个问题,每次连接时,都会弹出public key认证,如果不让它弹出,则按照下图,将password 认证移到最上面即可。
可以右键点Session,对所有的Session一次性更改为password 认证的方式
13. 刷入大量配置
当配置太多,CRT可能缓存过大,丢配置。如何让CRT直接从命令文件读取命令?每次一行,逐行执行?
命令文件test.txt
ifconfig -a
ls
lspci
lsusb
lspci |grep ethernet
#$language = "VBScript"
#$interface = "1.0"
' This script demonstrates one way to send a text file to a unix server
' This is equivalent to doing an "send ASICII" in a script
' Constants used by OpenTextFile()
Const ForReading = 1
Const ForWriting = 2
Sub Main
' Create an instance of the filesystem object so we can open a file
' Note: A runtime exception will be generated if 'myfile.txt' doesn't exist
set fso = CreateObject("Scripting.FileSystemObject")
set file = fso.OpenTextFile("C:\Users\Amber\Desktop\Pandas\test.txt",ForReading,False)
' Send a 'cat' command to direct everything we are about to send into a file
' The next line causes the script to wait until the 'cat' command has been
' sent(and executed) by the server.So that the data we`re about to send
' doesn`t get sent until redirected 'cat' command is actually in effect
' Send the file a line at a time
Do While file.AtEndOfStream <> True
str = file.Readline
crt.Screen.send str & Chr(13)
crt.Screen.WaitForString "#"
Loop
' Send an EOF character to end output to terminate 'cat'
'crt.Screen.send Chr(4)
End Sub
14. 批量创建Session<尚未成功>
folder,username,hostname,protocol,session_name
Example,root,192.168.146.128,ssh2,Example1
Example,root,192.168.146.136,ssh2,Example2
[参考]
1. https://www.bilibili.com/video/av75814903?from=search&seid=10099096660970433761