#!/bin/bash # Elizabeth Training Keep-Alive Script # Provides periodic input to keep training sessions active echo "=== Elizabeth Training Keep-Alive ===" echo "Started: $(date)" # Training prompts to keep session active TRAINING_PROMPTS=( "Please continue your training and analysis" "Share your latest insights and learning progress" "What have you discovered in your recent training?" "Continue with your autonomous learning cycle" "Provide a status update on your training progress" "What patterns are you identifying in your learning?" "Continue your analysis and share key findings" ) # Find active Elizabeth training process find_elizabeth_pid() { ps aux | grep "python3.*elizabeth_main.py.*interactive" | grep -v grep | awk '{print $2}' | head -1 } # Send input to process send_training_prompt() { local pid=$1 local prompt=$2 # Check if process exists and is interactive if [ -n "$pid" ] && [ -e "/proc/$pid/fd/0" ]; then echo "Sending training prompt to PID $pid: $prompt" echo "$prompt" > /proc/$pid/fd/0 return 0 else echo "No active interactive training process found" return 1 fi } # Main keep-alive loop COUNTER=0 MAX_ITERATIONS=100 SLEEP_DURATION=300 # 5 minutes while [ $COUNTER -lt $MAX_ITERATIONS ]; do echo "" echo "[$(date)] Keep-alive iteration $((COUNTER + 1))/$MAX_ITERATIONS" # Find active training process TRAINING_PID=$(find_elizabeth_pid) if [ -n "$TRAINING_PID" ]; then echo "Found training process: PID $TRAINING_PID" # Select random prompt PROMPT_INDEX=$((RANDOM % ${#TRAINING_PROMPTS[@]})) SELECTED_PROMPT="${TRAINING_PROMPTS[$PROMPT_INDEX]}" # Send keep-alive prompt if send_training_prompt "$TRAINING_PID" "$SELECTED_PROMPT"; then echo "Keep-alive prompt sent successfully" else echo "Failed to send keep-alive prompt" fi else echo "No active training process found - checking for restart..." # Check if training manager is running if ! ps aux | grep -q "training_manager.py" | grep -v grep; then echo "Training manager not running, attempting to restart..." cd /workspace/elizabeth-repo nohup python3 scripts/training_manager.py --start --mode interactive > /workspace/elizabeth_logs/training_manager.log 2>&1 & echo "Training manager restarted" fi fi # Wait before next iteration echo "Sleeping for $SLEEP_DURATION seconds..." sleep $SLEEP_DURATION COUNTER=$((COUNTER + 1)) done echo "" echo "=== Keep-Alive Completed ===" echo "Finished: $(date)" echo "Total iterations: $COUNTER"