#!/bin/bash # 补删 /var/lib/mysql(上一条脚本的整数判断写错了,误跳过) set -u echo "════════ 删除前的三重确认 ════════" echo " 1. 有没有 mysqld/mariadb 进程:" n=$(pgrep -f 'mysqld|mariadb' 2>/dev/null | wc -l) echo " $n 个" echo " 2. dpkg 里有没有 mysql/mariadb 包:" p=$(dpkg -l 2>/dev/null | grep -cE '^ii +(mysql|mariadb)' || true) echo " $p 个" echo " 3. 有没有相关 systemd 服务:" s=$(systemctl list-unit-files 2>/dev/null | grep -cE '^(mysql|mariadb)' || true) echo " $s 个" echo " 4. 目录大小:$(du -sh /var/lib/mysql 2>/dev/null | awk '{print $1}')" echo " 5. 有没有别的进程打开着里面的文件:" fuser -m /var/lib/mysql 2>/dev/null | wc -l | sed 's/^/ /' if [ "$n" -eq 0 ] && [ "$p" -eq 0 ] && [ "$s" -eq 0 ]; then echo echo " → 三项都是 0,确认是卸载残留的数据目录,删除" rm -rf /var/lib/mysql echo " ✓ 已删除" else echo echo " ! 还有引用,**不删**" fi echo echo "════════ 把剩余的调试脚本也移走 ════════" # 上一条只移走了一部分(通配符没覆盖全)。 # 现在把 /root 下**所有顶层** .sh/.py 都移进回收目录 —— # 中转的运行时代码在 /root/lanremote-relay/ 里,不受影响。 before=$(ls -1 /root/*.sh /root/*.py 2>/dev/null | wc -l) mkdir -p /root/.trash-debug for f in /root/*.sh /root/*.py; do [ -f "$f" ] || continue mv "$f" /root/.trash-debug/ 2>/dev/null done after=$(ls -1 /root/*.sh /root/*.py 2>/dev/null | wc -l) echo " /root 顶层脚本: $before -> $after" echo " 回收目录里的: $(ls -1 /root/.trash-debug 2>/dev/null | wc -l) 个" echo " ⚠ 没有真删,放在 /root/.trash-debug;确认中转一切正常后再 rm -rf" echo echo "════════ 确认中转没被影响 ════════" echo " relay 服务: $(systemctl is-active lanremote-relay)" echo " 隧道(quic): $(systemctl is-active lanremote-tunnel)" echo " 隧道(h2): $(systemctl is-active lanremote-tunnel-h2)" echo " 自检: $(curl -s --max-time 10 http://127.0.0.1:8080/v1/health | head -c 70)" echo echo " 中转目录完好: $(ls /root/lanremote-relay/ | tr '\n' ' ')" echo echo "════════ 最终空间 ════════" df -h / | sed 's/^/ /' echo du -xhd1 / 2>/dev/null | sort -rh | head -8 | sed 's/^/ /'