#!/bin/bash
yum -y
install sysstat
bc &>/dev/null
datename
=$(date +%Y%m%d-%H:%M:%S)
ip
=`ip a | grep inet|grep 255 |awk '{print $2}'`
tcp_sl
=`netstat -tnlp | wc -l`
tcp_name
=`netstat -tnlp | awk '{print $4,$7,$8}'|awk 'NR>2' | column -t`
banben
=`cat /etc/redhat-release`
user
=`whoami`
date1
=`date | awk '{print $1,$2,$3,$4,$5 }'`
cpu1
=`cat /proc/cpuinfo | grep name |awk -F":" '{print $2}'`
cpu_hz
=`cat /proc/cpuinfo |grep MHz |awk -F":" '{print $2}'`
bit
=`getconf LONG_BIT`
cpu_fz
=`uptime | awk -F"average:" '{print $2,$3}'`
cpu_zy
=`ps auxw | head -1;ps auxw|sort -rn -k4|head -5`
root_size
=`df -TH |grep root |awk '{print $3}'`
root_size1
=`df -TH |grep root |awk '{print $5}'`
root_size2
=`df -TH |grep root |awk '{print $6}'`
swap_size
=` free -h |grep wap |awk '{print $2}'`
swap_size1
=` free -h |grep wap |awk '{print $4}'`
mem_size
=`free -h |grep em |awk '{print $2}'`
mem_size1
=`free -h |grep em |awk '{print $4}'`
io1
=` iostat -x 1 1| grep sda |awk '{print $14}'`
io
=`iostat -x 1 1`
dlu
=`last | head`
if [ `echo "$io1 > 70" | bc` -eq 1
];then
io_zy
=高
else
io_zy
="正常"
fi
inode1
=`df -i |head -2`
ip_ll
(){
ipll1
=` cat /proc/net/dev | column -t`
echo "**(网.络.流.量.相.关)***********************************************************************
当前流量详细信息
$ipll1
------------------------------------------------------------------------------------------------
系统健康信息及常用服务检查
"
}
ping1
(){
ping -c 1 www.baidu.com
&>/dev/null
if [ $? -eq 0
];then
ping_tong
=能连接网络!
else
ping_tong
=不能连接网络!
fi
echo "------网络状态:$ping_tong "
}
nginx1
(){
rpm -qa
| grep nginx
&>/dev/null
if [ $? -eq 0
];then
netstat -tnlp
| grep nginx
&>/dev/null
if [ $? -eq 0
];then
echo "------nginx:服务状态正常! "
else
echo "------nginx:服务未启动! "
fi
else echo "------未安装nginx ! "
fi
}
httpd1
(){
rpm -qa
| grep httpd
&>/dev/null
if [ $? -eq 0
];then
netstat -tnlp
| grep httpd
&>/dev/null
if [ $? -eq 0
];then
echo "------httpd:服务状态正常! "
else
echo "------httpd:服务未启动! "
fi
else echo "------未安装httpd ! "
fi
}
mysql1
(){
rpm -qa
| grep mysql
&>/dev/null
if [ $? -eq 0
];then
netstat -tnlp
| grep mysql
&>/dev/null
if [ $? -eq 0
];then
echo "------mysql:服务状态正常! "
else
echo "------mysql:服务未启动! "
fi
else echo "------未安装mysql ! "
fi
}
keepalived1
(){
rpm -qa
| grep keepalived
&>/dev/null
if [ $? -eq 0
];then
netstat -tnlp
| grep keepalived
&>/dev/null
if [ $? -eq 0
];then
echo "------keepalived:服务状态正常! "
else
echo "------keepalived:服务未启动! "
fi
else echo "------未安装keepalived ! "
fi
}
redis1
(){
rpm -qa
| grep redis
&>/dev/null
if [ $? -eq 0
];then
netstat -tnlp
| grep redis
&>/dev/null
if [ $? -eq 0
];then
echo "------redis:服务状态正常! "
else
echo "------redis:服务未启动! "
fi
else echo "------未安装redis ! "
fi
}
service1
(){
echo " "
echo "-----------------系统服务检查----------------------"
runing1
=`systemctl list-units --type=service --state=running --no-pager | grep ".service"`
enable1
=`systemctl list-unit-files --type=service --state=enabled --no-pager | grep "enabled"`
runing2
=`systemctl list-units --type=service --state=running --no-pager | grep ".service"| wc -l`
enable2
=`systemctl list-unit-files --type=service --state=enabled --no-pager | grep "enabled"| wc -l`
echo " "
echo "-------------正在运行的服务.数量$runing2个-----------
$runing1
"
echo ""
echo "------------系统全部自启动服务.数量$enable2个 ---------
$enable1
"
}
jhrw
(){
team
=`cat /etc/passwd |cut -f 1 -d :`
for user
in ${team}
do
crontab -l -u
$user > /dev/null 2
>&1
if [ $? -eq 0
];then
user1
=`crontab -l -u $user`
user2
=`crontab -l -u $user |wc -l`
echo " "
echo "用户名:$user 计划任务数量:$user2个
--------计划任务信息-------
$user1"
echo ""
fi
done
}
userjc
(){
username
=`cat /etc/passwd |awk -F":" '{print $1}'`
for name
in $username
do
pass1
=`chage -l $name | column -t|awk 'NR==1';chage -l $name | column -t|awk 'NR==2'`
echo ""
echo "------用户:$name-------"
echo "$pass1"
done
}
echo "
-------------------------------------------------------------------------------------------
用户名称:$user
当前时间:$date1
系统版本:$banben $bit位
**(C.P.U.相.关)****************************************************************************
处理器名称:$cpu1
处理器频率:$cpu_hz 赫兹
--(c.p.u.负载)-----------------------------------------------------------------------------
处理器负载平均值:$cpu_fz (5分钟/10分钟/15分钟)
-------------------------------------------------------------------------------------------
前5个资源占用进程信息:
$cpu_zy
**(磁.盘.相.关)****************************************************************************
当前root根目录总容量为:$root_size
当前root更目录可用容量为:$root_size1 已用百分比$root_size2
-------------------------------------------------------------------------------------------
当前主分区iNode利用率详细信息
$inode1
-------------------------------------------------------------------------------------------
当前io占用$io_zy 详细信息输出
$io
**(内.存.相.关)****************************************************************************
当前内存总容量为:$mem_size
当前内存可用容量为:$mem_size1
当前交换分区总容量为:$swap_size
当前交换分区可用容量为:$swap_size1
**(I.P.相.关)******************************************************************************
当前ip
$ip
**(端.口.相.关)****************************************************************************
当前监听端口数量 $tcp_sl 个 !
-------------------------------------------------------------------------------------------
端口号 | 进程id / 对应端口进程
$tcp_name
" > /tmp/
$datename.log
ip_ll
>> /tmp/
$datename.log
ping1
>> /tmp/
$datename.log
echo " " >> /tmp/
$datename.log
echo "---------常用服务检查--------" >> /tmp/
$datename.log
nginx1
>> /tmp/
$datename.log
httpd1
>> /tmp/
$datename.log
mysql1
>> /tmp/
$datename.log
redis1
>> /tmp/
$datename.log
keepalived1
>> /tmp/
$datename.log
service1
>> /tmp/
$datename.log
echo "-----------登录检查-------------
$dlu" >> /tmp/
$datename.log
echo "----------计划任务查询----------" >> /tmp/
$datename.log
jhrw
>> /tmp/
$datename.log
echo "---------用户及密码检查---------" >> /tmp/
$datename.log
userjc
>> /tmp/
$datename.log
read -p
"(系统信息输出成功,查看输入数字'1')" sr
if [ $sr = 1
];then
clear
cat /tmp/
$datename.log
else
echo "输入有误,退出脚本!信息位置/tmp/$datename.log ,自行查看! "
exit
fi
--------------------当你发现自己突然嫉妒起其他人时,就请安静下来学习吧!--------------------
转载请注明原文地址:https://ipadbbs.8miu.com/read-63478.html