#!/bin/bash

echo "======================================"
echo "DataX 同步任务状态监控"
echo "======================================"
echo "检查时间: $(date '+%Y-%m-%d %H:%M:%S')"
echo "======================================"

# 检查产品同步日志
PRODUCTS_LOG_DIR="/Users/zksu/Developer/work/workcode/API-vendor/container/datax/log"
PRODUCTS_LOG=$(ls -t ${PRODUCTS_LOG_DIR}/products_sync_*.log 2>/dev/null | head -1)
if [ -f "$PRODUCTS_LOG" ]; then
    echo -e "\n产品同步："
    echo "最后执行时间：$(date -r $PRODUCTS_LOG '+%Y-%m-%d %H:%M:%S')"
    echo "日志文件：$PRODUCTS_LOG"
    echo "执行结果：$(tail -1 $PRODUCTS_LOG)"
    echo "日志大小：$(ls -lh $PRODUCTS_LOG | awk '{print $5}')"
else
    echo -e "\n产品同步："
    echo "未找到产品同步日志文件"
fi

# 检查订单同步日志
ORDERS_LOG=$(ls -t ${PRODUCTS_LOG_DIR}/orders_sync_*.log 2>/dev/null | head -1)
if [ -f "$ORDERS_LOG" ]; then
    echo -e "\n订单同步："
    echo "最后执行时间：$(date -r $ORDERS_LOG '+%Y-%m-%d %H:%M:%S')"
    echo "日志文件：$ORDERS_LOG"
    echo "执行结果：$(tail -1 $ORDERS_LOG)"
    echo "日志大小：$(ls -lh $ORDERS_LOG | awk '{print $5}')"
else
    echo -e "\n订单同步："
    echo "未找到订单同步日志文件"
fi

echo -e "\n======================================"
echo "监控结束"
echo "======================================"