4
头图

1. 系统资源监控

#!/bin/bash
# 监控CPU/内存/磁盘
echo "CPU负载: $(uptime | awk -F 'load average: ' '{print $2}')"
echo "内存使用: $(free -m | awk '/Mem/{print $3"MB/"$2"MB"}')"
echo "磁盘使用: $(df -h / | awk 'NR==2{print $5}')"

2. 进程监控脚本

#!/bin/bash
# 检测指定进程是否存在
ps -ef | grep "[n]ginx" || echo "Nginx未运行!"

3. 自动清理旧日志

#!/bin/bash
# 删除超过30天的日志
find /var/log -name "*.log" -type f -mtime +30 -delete

4. 批量用户创建

#!/bin/bash
# 从userlist.txt读取用户名创建用户
while read user; do
  useradd -m -s /bin/bash "$user"
done < userlist.txt

5. SSH登录失败监控

#!/bin/bash
# 统计最近10分钟SSH失败登录
grep "Failed password" /var/log/auth.log | grep "$(date -d '10 minutes ago' '+%b %_d %H:%M')"

6. 证书过期检查

#!/bin/bash
# 检查域名证书过期时间
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates

7. 自动系统更新

#!/bin/bash
# 安全更新(适合cron定时任务)
apt update && apt upgrade -y && apt autoremove -y

8. 磁盘空间告警

#!/bin/bash
# 当根分区使用超90%时触发告警
[ $(df / --output=pcent | tail -1 | tr -d '% ') -gt 90 ] && echo "磁盘告警!"

9. 网络连接统计

#!/bin/bash
# 统计ESTABLISHED状态连接数
netstat -ant | grep -c ESTABLISHED

10. 服务状态检查

#!/bin/bash
# 检查服务是否活跃
systemctl is-active nginx >/dev/null || systemctl restart nginx

11. 备份MySQL数据库

#!/bin/bash
# 每日数据库备份
mysqldump -u root -pPASSWORD dbname | gzip > /backup/db_$(date +%F).sql.gz

12. 大文件查找

#!/bin/bash
# 查找大于100MB的文件
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null

12. 大文件查找

#!/bin/bash
# 查找大于100MB的文件
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null

13. 同步服务器时间

#!/bin/bash
# 强制同步NTP时间
timedatectl set-ntp true && systemctl restart systemd-timesyncd

14. 检测恶意进程

#!/bin/bash
# 检测隐藏进程(无二进制文件)
ps -eo pid,comm,cmd | awk '$2=="(deleted)"'

15. 端口监听检测

#!/bin/bash
# 检查指定端口是否监听
ss -tuln | grep -q ":80 " && echo "80端口已监听"

16. 僵尸进程清理

#!/bin/bash
# 杀死所有僵尸进程
ps -eo stat,pid | awk '/Z/{print $2}' | xargs kill -9

17. 登录用户监控

#!/bin/bash
# 显示当前登录用户及IP
who | awk '{print $1,$5}' | sort | uniq

18. 系统信息摘要

#!/bin/bash
# 快速生成系统报告
echo "Hostname: $(hostname)"
echo "Kernel: $(uname -r)"
echo "Uptime: $(uptime -p)"

19. 批量杀进程

#!/bin/bash
# 通过进程名批量结束进程
pkill -9 -f "process_pattern"

20. 文件完整性校验

#!/bin/bash
# 生成系统关键文件MD5指纹
find /etc -type f -exec md5sum {} \; > /var/log/file_fingerprints.md5

21. 自动封禁IP

#!/bin/bash
# 封禁SSH失败超过5次的IP
grep "Failed password" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | awk '$1>5{print $2}' | xargs -I {} iptables -A INPUT -s {} -j DROP

22. 路由跟踪监控

#!/bin/bash
# 持续跟踪到目标主机的路由
mtr -n -c 10 example.com

23. 内存泄漏检测

#!/bin/bash
# 监控进程内存增长(替换PID)
watch -n 60 "ps -o pid,user,%mem,cmd -p PID"

24. 交换分区监控

#!/bin/bash
# 当swap使用超过50%时报警
[ $(free | awk '/Swap/{printf "%d", $3/$2*100}') -gt 50 ] && echo "Swap使用过高!"

25. 磁盘健康检查

#!/bin/bash
# 检测S.M.A.R.T状态(需要smartmontools)
smartctl -H /dev/sda | grep "test result"

26. 网络吞吐量测试

#!/bin/bash
# 快速带宽测试(安装iperf3)
iperf3 -c speedtest.server -p 5201

27. 系统日志分析

#!/bin/bash
# 统计最频繁的50条系统日志
journalctl --since "1 hour ago" | awk '{print $5}' | sort | uniq -c | sort -nr | head -50

28. 容器清理脚本

#!/bin/bash
# 清理已停止的Docker容器和镜像
docker system prune -a -f

29. 安全补丁检查

#!/bin/bash
# 检查可用的安全更新
apt list --upgradable | grep -i security

30. 自动配置防火墙

#!/bin/bash
# 基础防火墙配置(UFW)
ufw default deny incoming
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable

dblens数据库客户端[推荐]

https://sourceforge.net/projects/dblens-for-mysql

dblens数据库管理工具(dblens for mysql)
  • 🔧 可视化索引使用分析
  • 📊 AI 索引设计分析
  • 💡 智能索引优化建议
  • 📊 AI 快速设计表、视图、函数、事件、存储过程

    DBLens数据库管理工具
  • 🖥 可视化设计:拖拽式表结构设计,ER 关系图自动生成,降低建模门槛。
  • ⚡ 智能 SQL 开发:支持语法高亮、代码补全、执行计划分析,查询效率提升 50%+。
  • 独特优势 全中文支持:界面 / 文档 / 社区全面本土化,降低学习成本。
  • 跨平台适配:Windows/macOS/Linux 全平台兼容。

DBLens
171 声望78 粉丝

DBLens([链接]):高效的数据库管理工具。