紧承上文《CentOS 6系统优化脚本》,因为有时候一台虚拟机已经刷过了优化脚本,但是可能因为别的原因,这台虚拟机暂时搁置了。等过了一段时间之后,突然要用又不知道这台虚拟机是否已经优化过了,而重新使用cobbler刷一次系统又会耗费一定的时间,所以这个检测系统是否刷过优化脚本的shell脚本就诞生了。脚本不是特别准确,但是能针对上次的优化脚本做一个检查,如果已经刷过脚本,就会通过运行该脚本知道系统已经优化过了,可以立即投入使用,避免浪费时间重新再刷一次系统。如果是一个完全重新安装的CentOS 6.x,那结果也可以看出该虚拟机并未优化过,那么执行优化脚本优化一次即可。
#!/bin/bash ##################################################################################### #ThescriptisusedtocheckwhethertheoptimizescripthadbeenrunonCentOS6.x #CreatedbyJerry12356onMay16th,2016 ##################################################################################### ./etc/init.d/functions check_iptables(){ /etc/init.d/iptablesstatus>/dev/null2>&1 [$?-ne0]&&action"Optimizeiptables:"/bin/true||action"Optimizeiptables:"/bin/false } check_selinux(){ selinux_status=`getenforce` [$selinux_status=='Disabled']&&action"Optimizeselinux:"/bin/true||action"Optimizeselinux:"/bin/false } check_addusers(){ egrep"admin|nginx|zabbix"/etc/passwd>>/dev/null2>&1 [$?-eq0]&&action"Addusers:"/bin/true||action"Addusers:"/bin/false } check_install(){ rpm-qa|egrep"gcc|gcc-c++|openssh-clients|wget|make|cmake|curl|finger|nmap|tcp_wrappers|expect|lrzsz|unzip|zip|xz|ntpdate|lsof|telnet|vim|tree">/dev/null2>&1 [$?-eq0]&&action"Installsoftwares:"/bin/true||action"Installsoftwares:"/bin/false } check_repos(){ [-d/etc/yum.repos.d/bak]&&action"Updaterepos:"/bin/true||action"Updaterepos:"/bin/false } check_time(){ date-R|grep+0800>/dev/null2>&1 [$?-eq0]&&action"Settingtimezone:"/bin/true||action"Settingtimezone:"/bin/false crond_num=`crontab-l|grepntpdate|wc-l` [$crond_num-ge1]&&action"Synctime:"/bin/true||action"Synctime:"/bin/false } check_services(){ service_num=`chkconfig--list|grep3:on|egrep"crond|network|rsyslog|sshd"|wc-l` [$service_num-eq4]&&action"Optimizeservices:"/bin/true||action"Optimizeservices:"/bin/false } check_history(){ [$HISTSIZE-eq10000]&&action"Settinghistory:"/bin/true||action"Settinghistory:"/bin/false } check_kernel(){ conn_num=`ulimit-n` [$conn_num-eq2097152]&&action"Optimizekernel:"/bin/true||action"Optimizekernel:"/bin/false } check_hostname(){ [$HOSTNAME!='localhost.localdomain']&&action"Changehostname:"/bin/true||action"Changehostname:"/bin/false } check_iptables check_selinux check_addusers check_install check_repos check_time check_services check_history check_kernel check_hostname