Files
sanguo_quant_live/jiangwei-platform/scripts/test-windows-node.sh
T
2026-04-10 15:10:02 +08:00

109 lines
3.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Windows-Test-Node节点连接与测试脚本
# 使用方法:./test-windows-node.sh
# 颜色定义
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
log() { echo -e "${GREEN}$1${NC}"; }
warn() { echo -e "${YELLOW}⚠️ $1${NC}"; }
error() { echo -e "${RED}$1${NC}"; }
info() { echo -e "${BLUE}$1${NC}"; }
# Windows节点信息
WINDOWS_NODE="192.168.2.33"
WINDOWS_USER="administrator"
# 测试连接
info "测试Windows-Test-Node节点连接..."
# 尝试Ping节点(允许失败)
info "1/5: 测试网络连接(Ping..."
if ping -c 3 "$WINDOWS_NODE" >/dev/null 2>&1; then
log "Ping成功"
else
warn "Ping失败,但继续尝试其他方法"
info "请检查以下问题:"
info "1. Windows节点是否已启动"
info "2. 网络连接是否正常"
info "3. 防火墙是否允许Ping"
info "4. VPN连接是否已建立"
fi
# 尝试SSH连接(允许失败)
info "2/5: 测试SSH连接..."
if ssh "$WINDOWS_USER@$WINDOWS_NODE" "echo 'SSH连接成功'" >/dev/null 2>&1; then
log "SSH连接成功"
else
error "SSH连接失败"
info "请检查以下问题:"
info "1. Windows节点是否已启用SSH服务"
info "2. 用户名和密码是否正确"
info "3. 防火墙是否允许SSH连接"
exit 1
fi
# 检查Python环境
info "3/5: 检查Python环境..."
PYTHON_VERSION=$(ssh "$WINDOWS_USER@$WINDOWS_NODE" "python --version 2>&1 || python3 --version 2>&1")
if [ $? -eq 0 ]; then
log "Python环境已安装:$PYTHON_VERSION"
else
error "Python环境未安装"
info "请在Windows节点上安装Python"
exit 1
fi
# 检查AKShare安装
info "4/5: 检查AKShare安装..."
AKSHARE_INSTALLED=$(ssh "$WINDOWS_USER@$WINDOWS_NODE" "python -c 'import akshare; print(akshare.__version__)' 2>/dev/null || python3 -c 'import akshare; print(akshare.__version__)' 2>/dev/null")
if [ $? -eq 0 ]; then
log "AKShare已安装:$AKSHARE_INSTALLED"
else
error "AKShare未安装"
info "请在Windows节点上安装AKShare"
info "pip install akshare"
exit 1
fi
# 检查数据采集脚本是否存在
info "5/5: 检查数据采集脚本..."
SCRIPT_PATH="C:/sanguo_quant_live/zhaoyun-data/scripts/akshare_downloader.py"
if ssh "$WINDOWS_USER@$WINDOWS_NODE" "test -f '$SCRIPT_PATH'" >/dev/null 2>&1; then
log "数据采集脚本已存在:$SCRIPT_PATH"
else
warn "数据采集脚本不存在:$SCRIPT_PATH"
info "请确保脚本已同步到Windows节点"
fi
# 测试运行数据采集脚本
info "测试数据采集脚本..."
TEST_RESULT=$(ssh "$WINDOWS_USER@$WINDOWS_NODE" "python $SCRIPT_PATH --test 2>&1 || python3 $SCRIPT_PATH --test 2>&1")
if [ $? -eq 0 ]; then
log "数据采集脚本测试成功"
else
error "数据采集脚本测试失败"
info "错误信息:$TEST_RESULT"
exit 1
fi
# 输出Windows节点连接信息
echo ""
log "Windows-Test-Node节点检查完成!"
echo ""
info "Windows节点信息:"
info " IP地址:$WINDOWS_NODE"
info " 用户名:$WINDOWS_USER"
info " Python版本:$PYTHON_VERSION"
info " AKShare版本:$AKSHARE_INSTALLED"
echo ""
info "使用方法:"
info "在Windows节点上执行数据采集任务:"
info "ssh $WINDOWS_USER@$WINDOWS_NODE 'cd /c/sanguo_quant_live/zhaoyun-data && python scripts/akshare_downloader.py --symbols 510050 510300 --start-date 20210101 --end-date 20231231'"
echo ""
log "Windows-Test-Node节点已准备好使用!"