4.把linux服务器的cpu,内存,磁盘存到mysql数据库
#!/bin/bash # MySQL连接信息 MYSQL_USER="root" MYSQL_PASSWORD="12345678" MYSQL_HOST="localhost" MYSQL_DATABASE="linuxs" # 数据 cpu=$(top -b -n1 | grep "Cpu(s)" | awk '{print $2}') mem=$(free | grep Mem | awk '{print $3/$2 * 100.0}') lsblk=$(df -h / | awk '{print $5}' | tail -n 1 ) time=`date "+%F %X %A"` # 执行MySQL查询 mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -h $MYSQL_HOST $MYSQL_DATABASE << EOF INSERT INTO sys (cpu, mem, disk,update_time) VALUES ('$cpu', '$mem', '$lsblk','$time'); EOF