ImageVerifierCode 换一换
格式:DOCX , 页数:10 ,大小:61.10KB ,
资源ID:7629351      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7629351.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Linux服务器批量巡检脚本使用说明.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Linux服务器批量巡检脚本使用说明.docx

1、Linux服务器批量巡检脚本使用说明文件说明该Shell脚本旨在针对大量Linux服务器的巡检提供一种相对自动化的解决方案。脚本组成有三部分:shellsh.sh、checksh.sh、file.txt;这三个文件需放在一个文件夹下以root权限执行,缺一不可。脚本用法将要巡检的服务器的IP地址和对应的密码全部放入file.txt中保存,每行一个IP对应一个密码即可。然后用如下命令运行:#./ shellsh.sh file.txt 192.168.182.143 123456其中file.txt可以更换文件名,192.168.182.143为你想保存巡检日志的到哪个服务器的服务器IP,123

2、456为该服务器的密码。运行结果运行完后会在192.168.182.143服务器的/tmp目录下升成一个目录,即:GatherLogDirectory这个目录下即存放的是被巡检的服务器的巡检日志,这些日志以被巡检的服务器的IP命名,形如:192.168.182.146.log。在被巡检的服务器上会升成两个目录即:CheckScript、 LocalServerLogDirectory;其中CheckScript中是checksh.sh脚本,LocalServerLogDirectory中存放的是checksh.sh在该服务器上运行后升成的日志。测试结果我只在虚拟机上的三台Linux系统上测试过

3、,分别是Ubuntu、RedHat、Kali。运行正常,平均巡检一个服务器花费3分钟。脚本代码shellsh.sh#!/bin/bashlogin_info=$1gather_server_ip=$2gather_server_password=$3grep_ip=ifconfig | grep (:digit:1,3.)3:digit:1,3 -color=auto -o | sed -e 2,5dGatherPath=/tmp/GatherLogDirectoryCheckScriptPath=/tmp/CheckScriptif $# -ne 3 ; then echo -e Param

4、eters if fault!n echo -e Please using:$0 login_info gather_server_ipn echo -e For example: $0 IpAndPassword.txt $grep_ipn exit;fiif ! -x $GatherPath ;then mkdir $GatherPath echo -e The logs path is: $GatherPathficat $login_info | while read linedo server_ip=echo $line|awk print $1 server_password=ec

5、ho $line|awk print $2 login_server_command=ssh -o StrictHostKeyChecking=no root$server_ip scp_gather_server_checksh=scp checksh.sh root$server_ip:$CheckScriptPath/usr/bin/expectEOF set timeout 20 spawn $login_server_command expect *yes/no send yesr; exp_continue *password: send $server_passwordr exp

6、ect Permission denied, please try again. exit expect # send mkdir $CheckScriptPathr expect eof exitEOF /usr/bin/expectEOF set timeout 20 spawn $scp_gather_server_checksh expect *yes/no send yesr; exp_continue *password: send $server_passwordr expect Permission denied, please try again. exit expect C

7、onnection refused exit expect 100% expect eof exitEOF /usr/bin/expectEOF set timeout 60 spawn $login_server_command expect *yes/no send yesr; exp_continue *password: send $server_passwordr expect Permission denied, please try again. exit expect # send cd $CheckScriptPath;./checksh.sh $gather_server_

8、ip $gather_server_passwordr expect eof exitEOFdonechecksh.sh#!/bin/bash#Function:#This script checks the systems information,diskss information,performance,etc.of the#server#Author:#By Jack Wang#Company:#ShaanXi Great Wall Information Co.,Ltd.#GatherServerIpAddress is the servers IP address that gat

9、her the checking log#GatherServerPassword is the servers IP address that gather the checking log#GatherServerIpAddress=$1GatherServerPassword=$2#GetTheIpCommand is a command that you can get the IP address#GetTheIpCommand=ifconfig | grep (:digit:1,3.)3:digit:1,3 -color=auto -o | sed -e 2,5d#LogName

10、is a command that Your logsname#LogName=ifconfig|grep (:digit:1,3.)3:digit:1,3 -color=auto -o|sed -e 2,5decho -date +%Y%M%d#GatherLogPath is a path that collecting log path#LocalServerLogPath is local log path#GatherServerLogPath=/tmp/GatherLogDirectoryLocalServerLogPath=/tmp/LocalServerLogDirectory

11、#LinuxOsInformation is function that usege to collect OSs information#LinuxOsInformation()Hostname=hostnameUnameA=uname -aOsVersion=cat /etc/issue | sed 2,4dUptime=uptime|awk print $3|awk -F , print $1ServerIp=ifconfig|grep inet|sed 2,4d|awk -F : print $2|awk print $1ServerNetMask=ifconfig|grep inet

12、|sed 2,4d|awk -F : print $4|awk print $1ServerGateWay=netstat -r|grep default|awk print $2SigleMemoryCapacity=dmidecode|grep -P -A5 Memorys+Device|grep Size|grep -v Range|grep 0-9|awk -F : print $2|sed s/ t*/gMaximumMemoryCapacity=dmidecode -t 16|grep Maximum Capacity|awk -F : print $2|sed s/ t*/gNu

13、mberOfMemorySlots=dmidecode -t 16|grep Number Of Devices|awk -F : print $2|sed s/ t*/gMemoryTotal=cat /proc/meminfo|grep MemTotal|awk printf(MemTotal:%1.0fGBn,$2/1024/1024)|awk -F : print $2PhysicalMemoryNumber=dmidecode|grep -A16 Memory Device|grep Size:|grep -v No Module Installed|grep -v Range Si

14、ze:|wc -lProductName=dmidecode|grep -A10 System Information|grep Product Name|awk -F : print $2|sed s/ t*/gSystemCPUInfomation=cat /proc/cpuinfo|grep name|cut -d: -f2|awk print *$1,$2,$3,$4|uniq -c|sed s/ t*/gecho -e Hostname|$HostnamenUnamea|$UnameAnOsVersion|$OsVersionnUptime|$UptimenServerIp|$Ser

15、verIpnServerNetMask|$ServerNetMasknServerGateWay|$ServerGateWaynSigleMemoryCapacity|$SigleMemoryCapacitynMaximumMemoryCapacity|$MaximumMemoryCapacitynNumberOfMemorySlots|$NumberOfMemorySlotsnMemoryTotal|$MemoryTotalnPhysicalMemoryNumber|$PhysicalMemoryNumbernProductName|$ProductNamenSystemCPUInforma

16、tion|$SystemCPUInfomationPerformanceInfomation ()CPUIdle=top -d 2 -n 1 -b|grep CPpUu|grep id|awk print $5|awk -F % print $1CPUloadAverage=top -d 2 -n 1 -b|grep load average:|awk -F : print $5|sed s/ t*/gProcessNumbers=top -d 2 -n 1 -b|grep Tasks|awk -F : , print $3ProcessRunning=top -d 2 -n 1 -b|gre

17、p Tasks|awk -F : , print $8ProcessSleeping=top -d 2 -n 1 -b|grep Tasks|awk -F : , print $11ProcessStoping=top -d 2 -n 1 -b|grep Tasks|awk -F : , print $16ProcessZombie=top -d 2 -n 1 -b|grep Tasks|awk -F : , print $21UserSpaceCPU=top -d 2 -n 1 -b|grep CPpUu|head -1|awk -F : ,% print $4SystemSpaceCPU=

18、top -d 2 -n 1 -b|grep CPpUu|head -1|awk -F : ,% print $8ChangePriorityCPU=top -d 2 -n 1 -b|grep CPpUu|head -1|awk -F : ,% print $12WaitingCPU=top -d 2 -n 1 -b|grep CPpUu|head -1|awk -F : ,% print $19HardwareIRQCPU=top -d 2 -n 1 -b|grep CPpUu|head -1|awk -F : ,% print $23SoftwareIRQCPU=top -d 2 -n 1

19、-b|grep CPpUu|head -1|awk -F : ,% print $27MemUsed=top -d 2 -n 1 -b|grep Mem|awk -F : , print $11|tr -d a-zA-Z|awk printf(%dMn,$1/1024)MemFreeP=top -d 2 -n 1 -b|grep Mem|awk -F : , print $16|tr -d a-zA-Z|awk printf(%dMn,$1/1024)MemBuffersP= top -d 2 -n 1 -b|grep Mem|awk -F : , print $22|tr -d a-zA-Z

20、|awk printf(%dMn,$1/1024)CacheCachedP=top -d 2 -n 1 -b|grep Swap|awk -F : , print $24|tr -d a-zA-Z|awk printf(%dMn,$1/1024)CacheTotal=top -d 2 -n 1 -b|grep Swap|awk -F : , print $4|tr -d a-zA-Z|awk printf(%dMn,$1/1024)CacheUsed=top -d 2 -n 1 -b|grep Swap|awk -F : , print $14|tr -d a-zA-Z|awk printf(

21、%dMn,$1/1024)CacheFree=top -d 2 -n 1 -b|grep Swap|awk -F : , print $18|tr -d a-zA-Z|awk printf(%dMn,$1/1024)echo -e CPUIdle|$CPUIdlenCPUloadAverage|$CPUloadAveragenProcessNumbers|$ProcessNumbersnProcessRunning|$ProcessRunningnProcessSleeping|$ProcessSleepingnProcessStoping|$ProcessStopingnProcessZom

22、bie|$ProcessZombienUserSpaceCPU|$UserSpaceCPUnSystemSpaceCPU|$SystemSpaceCPUnChangePriorityCPU|$ChangePriorityCPUnWaitingCPU|$WaitingCPUnHardwareIRQCPU|$HardwareIRQCPUnSoftwareIRQCPU|$SoftwareIRQCPUnMemUsed|$MemUsednMemFreeP|$MemFreePnMemBuffersP|$MemBuffersPnCacheCachedP|$CacheCachedPnCacheTotal|$C

23、acheTotalnCacheUsed|$CacheUsednCacheFree|$CacheFreenOprateSystemSec () echo =UserLogin=wecho =FileUsed=df -ahecho =dmesgError=dmesg | grep errorecho =dmesgFail=dmesg | grep Failecho =BootLog=more /var/log/boot.log | grep -V OK | sed 1,6decho =route -n=route -necho =iptables -L=iptables -Lecho =netstat -lntp=netstat -lntpecho =netstat -antp=netstat -antpecho =BootLog=netstat -secho =netstat -s=lastecho =du -sh /etc/=du -sh /etc/echo =du -sh /boot/=du -sh /boot/echo =du -sh /dev/=du -sh /dev/echo =df -h=

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1