check_cpu-mem.sh
#!/bin/bash
cpu_num=$(top -n 1|awk -F ' ' '{print $10}'|awk 'NR==8'|awk -F '.' '{print $1}')
detail=$(top -n 1)
date=$(date +%Y-%m-%d\ %H:%M:%S)
if [ $cpu_num -ge 80 ];then
echo $date >> /soft/scripts/top_detail.txt
echo $detail >> /soft/scripts/top_detail.txt
echo "========================================" >> /soft/scripts/top_detail.txt
echo "========================================" >> /soft/scripts/top_detail.txt
echo "================这是分界线========================" >> /soft/scripts/top_detail.txt
echo "========================================" >> /soft/scripts/top_detail.txt
echo "========================================" >> /soft/scripts/top_detail.txt
fi
for i in {1..10}
do
mem_num=$(top -n 1|awk -F ' ' '{print $11}'|awk 'NR==8')
echo $mem_num |grep :
if [ $? -eq 0 ];then
sleep 2
echo '无效数据'
else
mem2_num=$(echo $mem_num|awk -F '.' '{print $1}')
echo $mem2_num >> /soft/scripts/top_detail.txt
if [ $mem2_num -ge 80 ];then
echo $date >> /soft/scripts/top_detail.txt
echo $detail >> /soft/scripts/top_detail.txt
echo "========================================" >> /soft/scripts/top_detail.txt
echo "========================================" >> /soft/scripts/top_detail.txt
echo "================这是分界线========================" >> /soft/scripts/top_detail.txt
echo "========================================" >> /soft/scripts/top_detail.txt
echo "========================================" >> /soft/scripts/top_detail.txt
fi
fi
done
check_php-fpm.sh
#!/bin/bash
php_num=$(ps -ef|grep php-fpm|wc -l)
if [ $php_num -ge 200 ];then
echo "web128 php进程剧增" | mail -s 'The Watch' 810540895@qq.com
fi
check_tcp.sh
#!/bin/bash
redis=$(netstat -n |grep TIME_WAIT|grep 6379|wc -l)
mysql=$(netstat -n |grep TIME_WAIT|grep 3306|wc -l)
max=$(netstat -n |awk -F ' ' '{print $5}'|sort -r |uniq -c|sort -n|awk -F ' ' '{print $1}' |tail -n 1)
max_detail=$(netstat -n |awk -F ' ' '{print $5}'|sort -r |uniq -c|sort -n|awk -F ' ' '{print $1"\t"$2}' |tail -n 5)
date=$(date +%Y-%m-%d\ %H:%M:%S)
totle=$(netstat -an|wc -l)
ESTABLISHED=$(netstat -anp|grep ESTABLISHED|wc -l)
ESTABLISHED_detail=$(netstat -anp|grep ESTABLISHED)
if [ $redis -ge 10000 ];then
echo "redis数量: " $redis "时间:" $date >> /soft/scripts/check_tcp.txt
fi
if [ $mysql -ge 10000 ];then
echo "mysql数量: " $redis "时间:" $date >> /soft/scripts/check_tcp.txt
fi
if [ "$max" -ge 10000 ];then
echo "最大可疑进程数量:" $max "可疑进程:" $max_detail "时间:" $date >> /soft/scripts/detail.txt
fi
if [ $totle -ge 10000 ];then
echo $date >> /soft/scripts/totle.txt
echo $(netstat -an) >> /soft/scripts/totle.txt
echo "========================================" >> /soft/scripts/totle.txt
echo "========================================" >> /soft/scripts/totle.txt
echo "================这是分界线========================" >> /soft/scripts/totle.txt
echo "========================================" >> /soft/scripts/totle.txt
echo "========================================" >> /soft/scripts/totle.txt
fi
if [ $ESTABLISHED -ge 300 ];then
echo $date >> /soft/scripts/ESTABLISHED_detail.txt
echo $ESTABLISHED_detail >> /soft/scripts/ESTABLISHED_detail.txt
echo "========================================" >> /soft/scripts/ESTABLISHED_detail.txt
echo "========================================" >> /soft/scripts/ESTABLISHED_detail.txt
echo "================这是分界线========================" >> /soft/scripts/ESTABLISHED_detail.txt
echo "========================================" >> /soft/scripts/ESTABLISHED_detail.txt
echo "========================================" >> /soft/scripts/ESTABLISHED_detail.txt
fi
nginx_log_mv.sh
#!/bin/bash
mv /txdata/server/openresty-1.13.6.2/nginx/logs/access.log /txdata/server/openresty-1.13.6.2/nginx/logs/access.log.$(date +%F)
if [ $? -eq 0 ];then
nginx -s reload
fi
sed.sh(替换某个文件夹下面的所有文件中的字符串为另一个字符串)
#!/bin/bash
for file in /biz-code/crontab/check/*
do
sed -i 's/dev/check/g' $file
done
restart_project.sh
#!/bin/bash
root_path='/biz-code'
git_path="https://gitee.com/xxxxx"
init_file=("init.sh.dev" "init.sh.check" "init.sh.release")
projects=("aristotle" "hume" "plato" "socrates" "marx");
read -p "请输入项目编号: 【'1:aristotle' '2:hume' '3:plato' '4:socrates' '5:marx'】 " project
cd $root_path
git_full_path=$git_path/${projects[$project-1]}.git
echo ""
echo "========================"
echo "当前路径:" $root_path
echo "需要下载的项目:" ${projects[$project-1]}
echo "git地址:" $git_full_path
echo ""
if [ ! -d ${projects[$project-1]} ];then
read -r -p "是否进行下载? [Y/n] " input
if [ $input != 'Y' ] &&[ $input != 'y' ]
then
echo "取消下载"
exit 0
fi
git clone $git_full_path
if [ $? -eq 0 ];then
echo '项目代码已下载'
else
echo '项目代码下载失败,请检查' $soucre_address
exit
fi
else
echo "========================"
echo "项目已经存在"
fi
cd $root_path/${projects[$project-1]}
path=`pwd`
echo ""
echo "========================"
echo "当前路径:" $path
echo ""
git pull
if [ $? -eq 0 ];then
echo "拉取代码成功"
else
echo "拉取代码失败"
exit
fi
read -p "请输入分支: " branch
git checkout $branch
git pull
if [ $? -eq 0 ];then
echo "分支切换成功"
else
echo "分支切换失败,请检查"
exit
fi
echo ""
echo "========================"
echo "当前分支:" $branch
echo ""
read -p "请输入环境编号:【1:测试服 2:验收服 3:正式服】: " env
if [[ $env > "3" || $env == "0" ]]
then
echo "环境数据错误"
exit 0
fi
docker_file=''
script_path=''
if [[ $project == 1 || $project == 2 ]];then
script_path='./Scripts'
docker_file=$script_path/docker-compose.yml
elif [[ $project == 3 ]];then
script_path='./scripts'
docker_file=$script_path/plato.compose
elif [[ $project == 4 ]];then
script_path='./scripts'
docker_file=$script_path/docker.compose
fi
cp $script_path/${init_file[$env-1]} init.sh && chmod +x init.sh && ./init.sh
if [ $? -eq 0 ];then
echo '环境切换成功'
else
echo '环境切换失败,请检查'
exit
fi
echo ""
echo "正在启动项目"
echo $docker_file
echo ""
docker-compose -f $docker_file stop
docker-compose -f $docker_file up -d
if [ $? -eq 0 ];then
echo '项目重新启动成功'
else
echo '项目重启失败,请检查'
fi
check_env.sh
#!/bin/bash
project=(redis elastic kibana web php hume aristotle)
for i in ${project[*]}
do
docker ps |grep $i
done
if [ $? -eq 0 ];then
echo ''
else
for i in ${project[*]}
do
docker restart $i
done
fi
|