BAT调用SECURECRT的VBS脚本功能自动化LINUX系统健康检查.pdf
《BAT调用SECURECRT的VBS脚本功能自动化LINUX系统健康检查.pdf》由会员分享,可在线阅读,更多相关《BAT调用SECURECRT的VBS脚本功能自动化LINUX系统健康检查.pdf(18页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、BAT 调用调用 SECURECRT 的的 VBS 脚本功能自动化脚本功能自动化 LINUX 系统健康检查系统健康检查最近负责管理的 LINUX 系统比较多,每天每台服务器登录检查一遍很烦。就用 BAT 调用 SECURECRT 的 VBS脚本,自动对所有服务器做自动检查。为了便于修改检查脚本,LINUX 检查脚本保存在本地,每次检查时,利用 SECURECRT 的 SFTP 功能上传到系统上,每次检查后再将检查日志下载到本地。Srv.list 主机列表文件主机列表文件需要检查的系统保存在 svr.list 文件中,文件格式为服务器的 IP 地址,SSH 端口号,主机名为了方便选择需要检查的系
2、统,有三个文件 srv.list,srvPRD.list,srvALL.list,可以通过 BAT 的参数选择不同的服务器列表。Dailycheck.batDailycheck.bat 是系统执行系统检查时的启动脚本,可以输入一个参数选择需要检查的服务器列给C:dailycheck.bat 不加参数,检查 svr.list 中的服务器C:dailycheck.batPRD 检查 svrPRD.list 中的服务器C:dailycheck.batALL 检查 svrALL.list 中的服务器Dailycheck.bat 从 srv.list 中读取服务器的 IP 地址,SSH 端口号,主机名称
3、,和用户名名、密码一起传入SECURECRT,SECURENT 再执行 VBS 脚本 dailycheck.vbsREMDAILYCheck.batechooffSetlocalENABLEDELAYEDEXPANSIONSetstrDate=%date:6,4%date:0,2%date:3,2%SetChecklog=d:OScheckos_dailycheck_%strDate%.logSetcheckDir=d:OSCheck%strDate%REM=setSvrList=d:OSChecksvr.listif%1=PRD(setSvrList=d:OSChecksvrPrd.list
4、 setSetChecklog=d:OScheckos_dailycheck_%strDate%_PRD.log )if%1=ALL(setSvrList=D:OSChecksvrAll.list SetChecklog=d:OScheckos_dailycheck_%strDate%_ALL.log )REM 为了安全每次执行时输入用户名和密码,如果不想这么麻烦,可以直接设置好用户名和密码。Set/PUsername=PleaseUserName:Set/PPassword=PleasePassword:echo:StartOSDailycheckingfor%1on%date%checkl
5、og%For/Ftokens=1,2,3delims=,%iin(%SvrList%)do(echo%date%:%k:%i%checklog%C:ProgramFilesVanDykeSoftwareSecureCRTsecurecrt.exe/titlebarOSCheck:%k:%i/NOMENU/NOTOOLBAR/SCR/ARG%UserName%/ARG%Password%/ARG%i/ARG%jREM 检查完毕后将下载到本地的检查日志移到一个目录中。ifnotexist%CheckDir%mkdir%CheckDir%Move/Yd:OSCheck*.log%checkDir%e
6、xit)Dailycheck.vbsDailycheck.vbs 执行 3 部分任务:1.将系统检查脚本 oscheck.sh 上传到服务器2.在服务器上执行系统检查脚本 oscheck.sh3.将检查日志下载到本地。#$language=VBScript#$interface=1.0SubMain dimobjTab,objSFTPTab dimstrHost,strUserid,strUserPwd,strRootPwd,strPort dimstrConnect IFcrt.arguments.count4then crt.Daiglog.MessageBox(NoEnoughParat
7、meters!)crt.quit exitsub ELSEstrUserid=crt.arguments(0)strUserPwd=crt.arguments(1)strHost=crt.arguments(2)strPort=crt.arguments(3)ENDIF =ConnecttoahostandstartOScheckdaily strConnect=/SSH2/P&strPort&/L&strUserId&/PASSWORD&strUserPwd&strHost setobjTab=crt.session.connectInTab(strConnect)objTab.screen
8、.synchronous=True CreateanSFTPtabassociatedwiththeexistingtab setobjSFTPTab=objTab.connectSFTP WaitfortheSFTPtabtobereadyforinput objSFTPTab.screen.synchronous=True crt.Sleep300 objSFTPTab.screen.Sendvbcr objSFTPTab.Screen.WaitForStringsftp Uploadoscheck.shind:OSChecktoremoteworkingDirectory/OSCheck
9、/objSFTPTab.Screen.Sendputboscheck.sh&vbcrlf objSFTPTab.screen.WaitForStringsftp objTab.activate()objTab.screen.send(sudoK)&chr(13)crt.sleep10 objTab.screen.send(sudosu)&chr(13)ObjTab.screen.waitforstring(sudo)ObjTab.screen.send(strUserPwd)&chr(13)objTab.screen.waitforstring(#)objTab.screen.send(cd/
10、OSCheck/)&chr(13)objTab.screen.waitforstring(Check)objTab.Screen.send(rmf/OSCheck/*.log;echor000)&chr(13)objTab.Screen.waitForString(r000)objTab.screen.send(sh./oscheck.sh)&chr(13)objTab.screen.waitforstring(successfully)objSFTPTab.activate()downloadthechecklogtod:OSCheckfromremoteworkingDirectory/O
11、SCheck objSFTPTab.Screen.Send(get b*.log)&vbcrlf objSFTPTab.screen.WaitForStringsftp ClosetheSFTPTab objSFTPTab.screen.send(exit)&vbcrlf objTab.activate()objTab.screen.send(exit)&chr(13)objTab.Screen.WaitForString($)objTab.Session.Disconnect objTab.close Done,quitSecureCRT crt.quitEndSubOscheck.shOs
12、check.sh 是统一的系统监控检测脚本。主要功能1.收集系统配置信息,将配置信息记录到配置日志中2.系统健康检查,如有报警将报警写到检查日志中。3.比较两次检查的系统配置,如果有变动,将变动写到检查日志中4.如果有本地检查脚本,执行一些服务器的特殊检查。Oscheck.sh 会产生 3 个日志。detail,config,check。Detail 中记录了本次检查的详细结果,config 是系统的配置问,check 是每次执行完脚本需要检查的日志文件,如果大小为 0,这台服务器就不用关注了。这个脚本是一点点加的,每次想到一点加一点,结构不是很好,凑活做参考吧。#!/bin/sh#=#Thi
13、s Scripts is used to collect Linux Configuration Data and health check daily.#=#-#Part 1 -Get the Basic Information#Part 2 -Get the Detail Information#Section 1 -System Information#Section 2 -Filesystem Information#Section 3 -VG Information#Section 4 -Services Configuration#Section 5 -The last 40 li
14、nes in syslog#Section 6 -Roots Mail#Section 7 -Login History since Last Day#Section 8 -Root Crontab and Error Log#Section 9 -Check Process#Section 10 -Network Information#Section 11 -Software Information#Part 3 -Check OVO Process#Part 4 -Check System Performance#Part 5 -run local check scripts if av
15、ailable#-LOGFILE=detail.hostname.date+%y%m%d.log ConfFile=conf.hostname.date+%y%m%d.log CheckLog=check.hostname.date+%y%m%d.log userid=whoami CheckDir=/OSCheck SectionN=0 FSThreshold=90 CPUThreshold=50 SWAPThreshold=30 cd$CheckDir#=#Preapre the output file#cp-f/dev/null$LOGFILE cp-f/dev/null$ConfFil
16、e cp-f/dev/null$CheckLog if id|cut-c1-6!=uid=0(;then echo This script must run as root!$CheckLog echo Script end unsuccessfully!eit 1 fi#Check Linux Distribution distrib=unknown if -f/etc/debian_version ;then if -f/etc/lsb-release ;then UBUNTU_VERSION=$(awk-F/DISTRIB_DESCRIPTION/print$2/etc/lsb-rele
17、ase)fi if$UBUNTU_VERSION;then distrib=$UBUNTU_VERSION UBUNTU=yes else distrib=Debian GNU/Linux Version cat/etc/debian_version UBUNTU=no fi DEBIAN=yes else DEBIAN=no fi if -f/etc/SuSE-release ;then distrib=head-1/etc/SuSE-release SUSE=yes else SUSE=no fi if -f/etc/redhat-release ;then distrib=head-1/
18、etc/redhat-release REDHAT=yes else REDHAT=no fi HostName=hostname-f IPAddress=ifconfig|grep inet addr|grep-v 127.0.0.1|awk-F:print$2|awk printKernelVer=uname-r CPUNum=cat/proc/cpuinfo|grep processor|wc-l CPUMHz=cat/proc/cpuinfo|grep MHz|uniq|awk-F:print$2 MemTotal=grep MemTotal/proc/meminfo|awk-F:pr
19、int$2 MemFree=grep MemFre/proc/meminfo|awk-F:print$2#=#Part 1:Get the Basic Information#=#echo=Part 1:Basic Information=echo System OS Health Check Date:date+%Y%m%d$LOGFILE echo Hostname :$HostName$LOGFILE echo Hostname :$HostName$ConfFile echo IP address :$IPAddress$LOGFILE echo IP address :$IPAddr
20、ess$ConfFile echo OS Version :$distrib$LOGFILE echo OS Version :$distrib$ConfFile echo OS Kernel Version :$KernelVer$LOGFILE echo OS Kernel Version :$KernelVer$ConfFile echo Processor Number :$CPUNum$LOGFILE echo Processor Number :$CPUNum$ConfFile echo Processsor CPU MHz :$CPUMHz$LOGFILE echo Total
21、Memory :$MemTotal$LOGFILE echo Total Memory :$MemTotal$ConfFile echo Free Memroy :$MemFree$LOGFILE echo System Uptime :uptime|awk-F,print$1,$2$LOG Upday=uptime|awk print$3 if$Upday-lt 1 then echo$Upday$CheckLog echo Server is reboot recently,please have a check$CheckLog fi#=#Part 2:Get the Detail In
22、formation#=#echo=Part 2:Detail Information =#echo-SectionN=expr$SectionN+1 echo Section$SectionN-OS Specific Release Information:$LOGFILE echo Section$SectionN-OS Specific Release Information:$ConfFile if -x/usr/bin/lsb_release then /usr/bin/lsb_release-a$LOGFILE 2/dev/null /usr/bin/lsb_release-a$Co
23、nfFile 2/dev/null else echo Linux Standard Base Verion$LOGFILE echo Linux Standard Base Verion$ConfFile fi#echo-SectionN=expr$SectionN+1 echo Section$SectionN-System Infomation:$LOGFILE echo CPU and Model Info:$LOGFILE cat/proc/cpuinfo$LOGFILE echo$LOGFILE echo System Ulimit:$LOGFILE ulimit-a$LOGFIL
24、E echo$ConfFile echo System Ulimit:$ConfFile ulimit-a$ConfFile echo$LOGFILE echo Hardware Info:$LOGFILE dmidecode$LOGFILE 2/dev/null echo$LOGFILE echo-SectionN=expr$SectionN+1 echo Section$SectionN-Filesystem Infomation:$LOGFILE echo Filesystem and Usage:$LOGFILE df-hlP$LOGFILE 2/dev/null echo$LOGFI
25、LE echo Local MountPoints:$ConfFile mount$ConfFile echo$ConfFile echo FileSystemSystem Tab:$ConfFile cat/etc/fstab$ConfFile echo$ConfFile echo NFS Filesystems:$ConfFile grep-vE#|*$/etc/exports$ConfFile#check if mounted Filesystem varied?mount mount.now if -f mount.ref ;then diff mount.now mount.ref
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- BAT 调用 SECURECRT VBS 脚本 功能 自动化 LINUX 系统 健康 检查
限制150内