将以下文件保存为check.sh脚本文件。
#!/bin/bash
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
echo "Host Name: " `hostname`
echo "OS Name: " `cat /etc/issue`
echo "Kernel Version " `uname -snrmpio`
echo "System Manufacturer " `dmidecode|grep "Manufacturer"|head -n 1|sed 's/Manufacturer://g'`
echo "System Model " `dmidecode|grep "Product Name"|head -n 1|sed 's/Product Name://g'`
echo "CPU Model " `grep "model name" /proc/cpuinfo|head -n 1|awk '{print $4" "$5" "$6 "\t" $7" "$8" "$9}'`
echo "MEM Size " `dmidecode -t memory|grep -v "No"|grep '[^a-z ]Size'|cut -d ':' -f 2|tr -s "\n" ","`
echo "Disk Model " `hdparm -i \`fdisk -l|grep Disk|cut -d ' ' -f 2|sed 's/://g'\`|grep Model|awk -F '[=]' '{print $2}'|sed 's/FwRev//g'`
echo "Disk Size " `fdisk -l|grep Disk|cut -d ' ' -f 2,3,4`
echo "Language " `echo $LANG`
echo "SELinux Status " `sestatus|sed 's/SELinux status://g'`
fws=$(service iptables status|grep "stop")
if [ "$fws" != "" ]; then
fwsend="Firewall is stopped."
else
fwsend="Firewall is running."
fi
echo "Iptables Status " `echo $fwsend`
webs=$(netstat -antp|grep 80)
if [ "$webs" != "" ]; then
websend="Web is running."
else
websend="Web is stopped."
fi
echo "Web Status " `echo $websend`
dbs=$(netstat -antp|grep 3306)
if [ "$dbs" != "" ]; then
dbsend="Database is running."
else
dbsend="Database is stopped."
fi
echo "DB Status " `echo $dbsend`
mails=$(netstat -antp|grep 25)
if [ "$mails" != "" ]; then
mailsend="Mail is running."
else
mailsend="Mail is stopped."
fi
echo "Mail Status " `echo $mailsend`
***s=$(ps -ef|grep -E 'pptpd|open***'|grep -v "grep")
if [ "$***s" != "" ]; then
***send="××× Server is running."
else
***send="××× Server is stopped."
fi
echo "××× Status " `echo $***send`
kas=$(ps -ef|grep "keepalived"|grep -v "grep")
if [ "$kas" != "" ]; then
kasend="Keepalived is running."
else
kasend="Keepalived is stopped."
fi
echo "Keepalived Status " `echo $kasend`
echo "TOP Status "
top -bn 1|head -n 5 >/tmp/tops.txt
cat /tmp/tops.txt|while read line
do
echo " " $line;
done
echo "User Login Count " `last |grep [a-zA-Z]|grep -v 'wtmp'|grep -v 'reboot'|cut -d ' ' -f 1|sort -nr|uniq -c|tr -s "\n" ","`
echo "User Last Login "
lastlog|grep -v "Never logged in"|grep -v "Latest"|awk '{print $1,$3,$5,$6,$9}' >/tmp/ulls.txt
cat /tmp/ulls.txt|while read line
do
echo " " $line;
done
echo "User Login Failed "
grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' /var/log/secure|sort|uniq -c >/tmp/ulfs.txt
cat /tmp/ulfs.txt|while read line
do
echo " " $line;
done
echo "Netstat Count "
netstat -n|grep ^tcp|awk '{print $NF}'|sort -nr|uniq -c >/tmp/nss.txt
cat /tmp/nss.txt|while read line
do
echo " " $line;
done
if [ -f /usr/local/nginx/logs/host.access_`date -d last-day +%Y%m%d`.log ]; then
echo "Nginx "`date -d last-day +%Y%m%d`" Log"
cut -d ' ' -f 10 /usr/local/nginx/logs/host.access_`date -d last-day +%Y%m%d`.log|sort|uniq -c >/tmp/nlcs.txt
cat /tmp/nlcs.txt|while read line
do
echo " " $line;
done
fi
最后chmod 755 check.sh,下面是该脚本执行结果: