日常巡检shell脚本

日常巡检shell脚本

2023年8月2日发(作者:)

⽇常巡检shell脚本⽇常巡检脚本运维⽇常巡检脚本#!/bin/bashos_sys(){#系统信息os_type=`uname`echo "操作系统的类型: $os_type"os_version=`cat /etc/redhat-release`echo "操作系统的版本号:$os_version"os_ker=`uname -r`echo "操作系统的内核版本:$os_ker"os_time=`date +%F_%T`echo "服务器当前的运⾏时间:$os_time"os_last_reboot=`uptime |awk '{print $3,$4}'| awk -F ',' '{print $1}'`echo "服务器最后重启时间: $os_last_reboot"os_hostname=`hostname`echo "服务器的主机名: $os_hostname"echo " "}os_network(){#⽹络信息which ifconfig &> /dev/nullif [ $? -gt 0 ];then yum -y install net-tools &>/dev/nullfiip_addr=$(ifconfig ens32 |awk '/netmask/{print $2}')echo "服务器的IP地址为:${ip_addr}"ping -c1 &> /dev/nullif [ $? -eq 0 ];then echo -e "033[5;33m服务器的⽹络正常033[0m"else echo -e "033[5;34m数据异常请检查⽹路033[0m"fiRX=$(ifconfig ens32 | grep RX | sed -n '1p' | awk '{print $(NF-1),$NF}')echo "⽹卡流⼊的量为:${RX}"TX=$(ifconfig ens32 | grep TX | sed -n '1p' | awk '{print $(NF-1),$NF}')echo "⽹卡流出的量为:${TX}"echo " "}#cpucpu_info(){cpu_num=$(cat /proc/cpuinfo |grep "physical id" | sort |uniq |wc -l)echo "cpu的物理个数为:${cpu_num}"cpu_core=$(cat /proc/cpuinfo |grep "core id" |sort |uniq |wc -l)echo "cpu的核⼼个数为:${cpu_core}"cpu_model=$(cat /proc/cpuinfo |grep "model name" |uniq |awk '{print $4,$6,$7,$9}')echo "cpu的型号:${cpu_model}"echo " "}#memmem_info(){#内存总⼤⼩mem_total=`free | awk '/Mem/{print $2}'`echo "内存总⼤⼩: $mem_total"#已使⽤内存mem_used=`free | awk '/Mem/{print $3}'`echo "已⽤内存⼤⼩:$mem_used"#剩余内存⼤⼩mem_free=`free | awk '/Mem/{print $4}'`echo "剩余内存⼤⼩:$mem_free"#已使⽤内存百分⽐p_bfb=$(free | grep Mem | awk '{print $3/$2 * 100.0}')echo "已使⽤内存百分⽐:${p_bfb}%"#剩余内存百分⽐

s_bfb=$(free | grep Mem | awk '{print $4/$2 * 100.0}')echo "剩余内存百分⽐:${s_bfb}%"echo " "}#disk#磁盘总量disk_info(){disk_total=$(lsblk |awk '/disk/{print $4}')echo "磁盘总量为:${disk_total}"count=($(df -Tm |egrep -v tmpfs |sed '1d' |awk '{print $5}'))sum=0for i in ${count[@]}dolet sum=sum+$idonesumb=($sum/1024)echo "剩余磁盘总量为 $sum M"} #while : #do os_sys os_network cpu_info mem_info disk_info #sleep 5 #doneNginx⽇志每天切割压缩#!/bin/bash#Nginx⽇志每天切割压缩#将当前的nginx⽇志先按照当天⽇期进⾏重命名接着进⾏压缩,最后是新建空⽩的nginx⽇志⽂件,并重新载⼊nginxnginx_log="/usr/local/nginx_log"if [[ ! -f $nginx_log ]];then mkdir -p $nginx_logficd /var/log/nginx/newAccessLog="access`date +%Y-%m-%d`.log"newErrorLog="error`date +%Y-%m-%d`.log"mv $newAccessLog && mv $newErrorLog#创建⽇志⽂件touch #reload Nginxsystemctl reload nginx#压缩⽇志⽂件tar -zcvf $ $newAccessLog --remove-files &>/dev/nulltar -zcvf $ $newErrorLog --remove-files &>/dev/nullmv *. $nginx_log循环探测全⽹主机并记录#!/bin/bashfor i in {2..254}doip=192.168.100.$iping -c1 -W1 $ip &>/dev/null if [ $? -eq 0 ];then echo "$ip" | tee -a fidoneExpect实现SSH免交互登陆#需提前安装expect软件包yum install expect tcl tclx tcl-devel -y#需提前⽣成公钥ssh-keygen#!/bin/bashfor i in {2..254}do{ip=192.168.100.$iping -c1 -w1 $ip &>/dev/null if [ $? -eq 0 ];then echo $ip/usr/bin/expect <<-EOFset timeout 10spawn ssh-copy-id $ipexpect { "yes/no" { send "yesr";exp_continue } "password:" { send "123456r" } #密码⾃定义}expect eofEOF fi} &donewaitecho "Complete"

发布者:admin,转转请注明出处:http://www.yc00.com/news/1690916620a462861.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信