#!/bin/bash
SERVER_IP="45.61.60.10"
SERVER_USER="root"
SERVER_PASS="UQb9TgSwC@vwhEM"

# 使用 expect 自动登录并执行检查命令
/usr/bin/expect <<EOF
set timeout 60
spawn ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP

expect {
    "password:" { send "$SERVER_PASS\r" }
    "yes/no" { send "yes\r"; exp_continue }
}

expect "#"
send "echo '=== SYSTEM INFO ==='\r"
send "uname -a\r"

send "echo '=== PORT 3001 (Node) ==='\r"
send "netstat -tulpn | grep 3001\r"

send "echo '=== PM2 STATUS ==='\r"
send "pm2 list\r"

send "echo '=== NGINX CONFIG TEST ==='\r"
send "nginx -t\r"

send "echo '=== FIND CCDW.XYZ CONFIG ==='\r"
# 尝试在常见位置搜索域名配置
send "find /etc/nginx /www/server/nginx /usr/local/nginx -name '*ccdw.xyz*' 2>/dev/null\r"

send "exit\r"
expect eof
EOF
