#!/bin/bash
# Agent监控脚本
AGENT=$1

echo "$(date) - ${AGENT} 启动监控"

while true; do
  # 检查是否有.task文件
  TASK_FILE=$(ls management/agents/${AGENT}/*.task 2>/dev/null | head -1)
  
  if [ -n "$TASK_FILE" ]; then
    echo "$(date) - ${AGENT} 发现新任务: $(basename $TASK_FILE)"
    
    # 读取任务内容
    TASK_CONTENT=$(cat "$TASK_FILE")
    echo "$(date) - ${AGENT} 任务内容:"
    echo "$TASK_CONTENT"
    
    # 删除.task文件
    rm "$TASK_FILE"
    echo "$(date) - ${AGENT} 完成任务"
  fi
  
  sleep 30
done