出来上面的连接外 下面也是总结的
日常巡检
#!/bin/bash
echo "系统巡检脚本:Version `date +%F`"
echo -e "\033[33m*******************************************************系统检查 *******************************************************\033[0m"
echo "系统:`uname -a | awk '{print $NF}'`"
echo "发行版本:`cat /etc/redhat-release`"
echo "内核:`uname -r`"
echo "主机名:`hostname`"
echo "SELinux:`/usr/sbin/sestatus | grep 'SELinux status:' | awk '{print $3}'`"
echo "语言/编码:`echo $LANG`"
echo "当前时间:`date +%F_%T`"
echo "最后启动:`who -b | awk '{print $3,$4}'`"
echo "运行时间:`uptime | awk '{print $3}' | sed 's/,//g'`"
echo -e "\033[33m*******************************************************CPU检查 *******************************************************\033[0m"
echo "物理CPU个数: `cat /proc/cpuinfo | grep "physical id" | awk '{print $4}' | sort | uniq | wc -l`"
echo "逻辑CPU个数: `cat /proc/cpuinfo | grep "processor" | awk '{print $3}' | sort | uniq | wc -l`"
echo "每CPU核心数: `cat /proc/cpuinfo | grep "cores" | awk '{print $4}'`"
echo "CPU型号: `cat /proc/cpuinfo | grep "model name" | awk -F":" '{print $2}'`"
echo "CPU架构: `uname -m`"
echo -e "\033[33m*******************************************************内存检查 *******************************************************\033[0m"
echo "总共内存:`free -mh | awk "NR==2"| awk '{print $2}'`"
echo "使用内存:`free -mh | awk "NR==2"| awk '{print $3}'` "
echo "剩余内存: `free -mh | awk "NR==2"| awk '{print $4}'`"
echo -e "\033[33m*******************************************************硬盘检查 *******************************************************\033[0m"
echo "总共磁盘大小:`df -hT | awk "NR==2"|awk '{print $3}'`"
echo -e "\033[33m*******************************************************网络检查 *******************************************************\033[0m"
echo `ip a | grep eno | awk "NR==2" | awk '{print $NF,":",$2}'`
echo "网关:`ip route | awk 'NR==1'| awk '{print $3}'`"
echo "DNS: `cat /etc/resolv.conf | grep "nameserver" | awk '{print $2}'`"
ping -c 4 www.baidu.com > /dev/null
if [ $? -eq 0 ];then
echo "网络连接:正常"
else
echo "网络连接:失败"
fi
echo -e "\033[33m*******************************************************安全检查 *******************************************************\033[0m"
echo "登陆用户信息:`last | grep "still logged in" | awk '{print $1}'| sort | uniq`"
md5sum -c --quiet /etc/passwd > /dev/null 2&>1
if [ $? -eq 0 ];then
echo "文件未被串改"
else
echo "文件被串改"
fi
分库
#!/bin/bash
#MySQL分库自动备份方案
DB_LIST=$(mysql -uroot -s -e "show databases;" | grep -v "Database")
DB_DIR=msyql_backup_`date +%F`
[ ! -d $DB_DIR ] && mkdir $DB_DIR
for i in $DB_LIST
do
#mysqldump -uroot --skip-lock-tables -B $i > ${DB_DIR}/${i}.sql
mysqldump -uroot -B $i > ${DB_DIR}/${i}.sql 2>/dev/null
done
分表
#!/bin/bash
#MySQL分表自动备份方案
DB_LIST=$(mysql -uroot -s -e "show databases;" | grep -v "Database")
DB_DIR=msyql_backup_`date +%F`
[ ! -d $DB_DIR ] && mkdir $DB_DIR
for i in $DB_LIST
do
for j in `mysql -uroot -s -e "use $i;show tables;" | grep -v Tables_in_mysql`
do
mysqldump -uroot ${i} ${j} > ${DB_DIR}/${i}_${j}.sql 2>/dev/null
done
done
done删除文件
#!/bin/bash
while :
do
read -p "请输入您想要删除的文件:<<" file
echo "您想要删除的文件是:$file"
read -p "确认要删除吗?(Y/N)" cmd1
case $cmd1 in
Y|y)
if [ -e $file ]; then
count=$(rpm -qa |grep rsync|wc -l)
if [ $count -ne 0 ]; then
echo "rsync 已经安装了"
else
yum -y install rsync
fi
netstat -lptnu|grep 873
if [ $? -eq 0 ]; then
echo "rsync service 已经运行了"
else
systemctl start rsyncd
fi
#开始备份文件
backup_dir="/usr/local/src/backup"
[ -d ${backup_dir} ] || mkdir ${backup_dir}
#开始执行备份操作:
rsync -av /tmp/abc ${backup_dir}
echo "input Y:delete!"
echo "input y:no delete!"
read -p "您是否真的真的要删我?(Y|y):<<" cmd2
case $cmd2 in
Y)
echo "start 删除文件:$file"
rm -rf $file
echo "文件恢复路径:${backup_dir}"
;;
y)
echo "no delete"
exit
;;
esac
else
echo "start touch file:$file"
touch $file
exit
fi
;;
N|n)
echo "不删除$file"
exit
;;