巡检脚本

别说谁变了你拦得住时间么 提交于 2019-12-13 11:54:19

#巡检脚本
#!/bin/bash
leixing=uname
echo “系统类型leixing"banben=cat/etc/redhatreleaseecho"leixing" banben=`cat /etc/redhat-release` echo "系统版本banben”
neihe=uname -a|awk '{print $3}'
echo “系统内核neihe"shijian=date+echo"neihe" shijian=`date +%F_%T` echo "系统时间shijian”
yunxing=uptime |awk '{print $3,$4}'|awk -F , '{print $1}'
echo “系统运行时间$yunxing”
chongqi=who -b|awk '{print $3}'
echo “系统重启时间chongqi"mingcheng=hostnameecho"chongqi" mingcheng=`hostname` echo "本机名称mingchen”
####################################################################################
#网络监测

#!/bin/bash
ip=ifconfig |grep -w inet|awk '{print $2}'
echo “本机$ip”
curl -I http://www.baidu.com
if [ ?eq0];thenecho"访ok"elseecho""ficpuid=grep"physicalid"/proc/cpuinfosortuniqwclecho"cpu? -eq 0 ];then echo "访问网络是ok的" else echo "网络异常" fi cpuid=`grep "physical id" /proc/cpuinfo |sort |uniq |wc -l` echo "cpu的数量cpuid"
cpucores=grep "cores" /proc/cpuinfo |sort |uniq |awk -F ':' '{print $2}'
echo “cpu的核心数$cpucores”
cpumod=grep "model name" /proc/cpuinfo|awk -F ':' '{print $2}'
echo “cpu的型号$cpumod”
rong=free -m|grep "Mem"|awk '{print $2}'
echo “内存容量$rong”
sheng=free -m|grep "Mem"|awk '{print $4}'
echo “剩余内存容量$sheng”

##################################################################################

#磁盘容量
#!/bin/bash
disksize=0
cipan=free -m |grep Swap|awk '{print $2}'
echo “交换分区容量$cipan”
fenqu=(df -T|grep -v "tmpfs"|sed '1d'|awk '{print $3}')
for ((i=0;i<echo ${#fenqu[@]};i++))
do
disksize=expr $disksize + ${fenqu[$i]}
done
((disktotal=(disksize+disksize+cipan)/1024/1024))
echo “磁盘总容量:$disktotal”
##########################################################################
ddos

#!/bin/bash
netstat -an|grep “ESTABLISHED”|awk ‘{print $4}’|awk -F “:” ‘{print $1}’|sort |uniq |head -n10 >>dropip
for ip in cat dropip
do
if [[ $ip =~ “192” ]] || [[ $ip =~ “127” ]];then
echo “pass”
else
echo $ip
cmd=iptables -I INPUT -p tcp -s $ip -j DROP
$cmd
echo “iptables -I INPUT -p tcp -s $ip -j DROP” >> /var/log/ddos
fi
done
#########################################################################

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!