SecureCRT脚本

        工作中需要通过SecureCRT管理多台服务器,脚本可以省去大量的体力工作,下面代码是查看各个服务器上某个进程是否在运行。

'@Script: language="VBScript"
'@Author: HC
Dim outputFile, serverFile, fout
Dim outputPath, serverPath
Dim user, pwd, ip, sname
outputPath = "C:\Users\haochao\Desktop\out.txt"
serverPath = "C:\Users\haochao\Desktop\server.txt"
Set fout = CreateObject("Scripting.FileSystemObject")
Set outputFile = fout.OpenTextFile(outputPath, 2, True)
Set serverFile = fout.OpenTextFile(serverPath, 1, False)

Sub main()
	crt.Screen.Synchronous = True
	Dim server
	Dim arr
	Do While serverFile.AtEndOfStream <> True
		server = serverFile.ReadLine
		server = trim(server)
		arr    = Split(server)
		ip     = arr(0)
		user   = arr(1)
		pwd    = arr(2)
		sname  = arr(3)
		Call connect()
	Loop
	crt.Screen.Synchronous = False	
    Call openFile()
End Sub

Sub connect()
	Dim cmd
	cmd = "/ssh2 /L " & user &" /PASSWORD " & pwd & " /C 3DES " & ip
	On Error Resume Next
	crt.Session.Connect cmd
	if Err.Number <> 0 Then
		outputFile.Write sname & " fail to connect!!!" & vbCrLf
	Else
		Call process()
	End If
	crt.Session.Disconnect
End Sub

Sub process()
	crt.Screen.Send "ps -ef|grep AppServer|grep -v grep" & vbCr
	If crt.Screen.WaitForStrings("AppServer", 1) <> False Then
		outputFile.Write sname & " is running..." & vbCrLf
	Else 
		outputFile.Write sname & " is stop!!!" & vbCrLf
	End If
End Sub

Sub openFile()
	Dim ws
	Set ws = CreateObject("wscript.shell") 
	ws.run outputPath
End Sub


你可能感兴趣的:(SecureCRT脚本)