#!/bin/bash
#Date: 13:19 2017-12-28
#Author: create by xpp
#QQ: 610109797
#Blog: www.
#version:1.1
. /etc/init.d/functions
##################################config######################################
#date
DATE=`date +"%y-%m-%d %H:%M:%S"`
#ip
IPADDR=`grep "IPADDR" /etc/sysconfig/network-scripts/ifcfg-eth0|cut -d= -f 2 `
#hostname
HOSTNAME=`hostname -s`
#user
USER=`whoami`
#disk_check
DISK_SDA=`df -h |grep -w "/" |awk '{print $5}'`
#cpu_average_check
cpu_uptime=`cat /proc/loadavg|awk '{print $1,$2,$3}'`
##################################function#####################################
#time sync
syncSysTime(){
echo "================配置时间同步====================="
\cp /var/spool/cron/root /var/spool/cron/root.$(date +%F) 2>/dev/null
NTPDATE=`grep ntpdate /var/spool/cron/root 2>/dev/null |wc -l`
if [ $NTPDATE -eq 0 ];then
echo "#times sync by lee at $(date +%F)" >>/var/spool/cron/root
echo "*/5 * * * * /usr/sbin/ntpdate time.windows.com >/dev/null 2>&1" >> /var/spool/cron/root
fi
echo '#crontab -l'
crontab -l
action "配置时间同步完成" /bin/true
echo "================================================="
echo ""
sleep 2
}
sysyh(){
echo "================系统优化====================="
/etc/init.d/iptables stop #这个是关闭防火墙命令,学习环境
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.cc #修改yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum update -y
yum install tree telnet dos2unix sysstat lrzsz nc nmap -y
yum groupinstall "Development Tools"
action "系统优化完成" /bin/true
echo "================================================="
echo ""
sleep 2
}
: '
inlamp(){
}
'
###################################menu###################################################
uid=`id | cut -d\( -f1 | cut -d= -f2`
if [ $uid -ne 0 ];then
action "Please run this script as root." /bin/false
exit 1
fi
while true
do
clear
echo "========================================"
echo ' Welcome to my tools '
echo "========================================"
cat << EOF
|------------------------------------------|
| DATE :$DATE |
| Author :xpp |
| QQ :610109797 |
| Blog :www. |
| version :1.1 |
-------------------------------------------
|********是否执行下一步优化系统******* |
-------------------------------------------
EOF
read -p "please input: [yes/no] : " input
if [ "$input" = "yes" ];then
syncSysTime
sysyh
elif [ "$input" = "no" ];then
exit 1
else
echo 'you must input yes or no'
echo 'input ERROR'
exit 4
fi
done