触发器
基于终端输出内容的自动化工具。它能在检测到屏幕显示特定字符串(如“password:”、“error”)时,自动执行预设动作(发送文本、执行脚本、播放声音),从而实现运维自动化、登录跳板机、高亮日志或自动响应错误。
脚本
使用流程
使用 [脚本 -> 开始录制] 记录下基本操作
使用 [停止录制],保存为 .vbs 后缀的文件
交给 AI 工具进行优化修改
示例:3000次重启测试
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| Sub Main Dim i, test_count Dim fso, logFile, logPath Dim startTime, currentTime i = 0 test_count = 3000 logPath = "C:\device_reboot_log.txt" Set fso = CreateObject("Scripting.FileSystemObject") Set logFile = fso.OpenTextFile(logPath, 8, True) startTime = Now() logFile.WriteLine("===== 设备重启脚本开始执行:" & startTime & " =====") logFile.WriteLine("总计划执行次数:" & test_count) logFile.WriteLine("----------------------------------------") xsh.Screen.Synchronous = True Do While i < test_count On Error Resume Next Err.Clear currentTime = Now() logFile.WriteLine("") logFile.WriteLine("第 " & (i+1) & " 次重启尝试(开始时间:" & currentTime & ")") xsh.Screen.Send("reboot" & vbCrLf) xsh.Session.Sleep(1000) If Err.Number <> 0 Then logFile.WriteLine("第 " & (i+1) & " 次重启失败:" & Err.Description) Else logFile.WriteLine("第 " & (i+1) & " 次重启命令已发送,等待设备恢复...") xsh.Session.Sleep(300000) logFile.WriteLine("第 " & (i+1) & " 次重启后等待完成") End If i = i + 1 On Error Goto 0 Loop logFile.WriteLine("----------------------------------------") logFile.WriteLine("脚本执行结束(结束时间:" & Now() & ")") logFile.WriteLine("实际执行次数:" & i & " 次") logFile.WriteLine("总耗时:" & DateDiff("n", startTime, Now()) & " 分钟") logFile.Close Set logFile = Nothing Set fso = Nothing MsgBox "重启脚本执行完成!共执行 " & i & " 次,日志已保存至:" & logPath End Sub
|