CentOS 6 system optimization detection script
Keep up with the above CentOS 6 system optimization script, because sometimes a virtual machine has been flushed with the optimization script, but this virtual machine may be temporarily shelved for other reasons. After waiting for a while, it will take some time for you to suddenly use it and you don't know if this virtual machine has been optimized. It will take some time to re-use cobbler to fl the system, therefore, the shell script used to check whether the system has flushed the optimization script is born. The script is not very accurate, but it can be checked for the last optimization script. If the script has been flushed, it will be known that the system has been optimized by running the script and can be put into use immediately, avoid wasting time refresh the system. If it is a fully reinstalled CentOS 6.x, the result can also be seen that the virtual machine has not been optimized, then execute the optimization script to optimize it once.
#!/bin/bash
#####################################################################################
#ThescriptisusedtocheckwhethertheoptimizescripthadbeenrunonCentOS6.x
#CreatedbyJerry12356onMay16th,2016
#####################################################################################
.
/etc/init
.d
/functions
check_iptables(){
/etc/init
.d
/iptables
status>
/dev/null
2>&1
[$?-
ne
0]&&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/null
2>&1
[$?-
eq
0]&&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/null
2>&1
[$?-
eq
0]&&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/null
2>&1
[$?-
eq
0]&&action
"Settingtimezone:"
/bin/true
||action
"Settingtimezone:"
/bin/false
crond_num=`
crontab
-l|
grep
ntpdate|
wc
-l`
[$crond_num-
ge
1]&&action
"Synctime:"
/bin/true
||action
"Synctime:"
/bin/false
}
check_services(){
service_num=`chkconfig--list|
grep
3:on|
egrep
"crond|network|rsyslog|sshd"
|
wc
-l`
[$service_num-
eq
4]&&action
"Optimizeservices:"
/bin/true
||action
"Optimizeservices:"
/bin/false
}
check_history(){
[$HISTSIZE-
eq
10000]&&action
"Settinghistory:"
/bin/true
||action
"Settinghistory:"
/bin/false
}
check_kernel(){
conn_num=`
ulimit
-n`
[$conn_num-
eq
2097152]&&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