Team Ai
Apppublic

shell2k/test1

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
setup_cron.sh45 linesDownload Raw Back to root
1#!/bin/bash2 3# Script to set up cron job for health monitoring4# This script adds a cron job to check the FastAPI health endpoint every hour5 6SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"7HEALTH_SCRIPT="$SCRIPT_DIR/health_check.sh"8 9echo "Setting up health monitoring cron job..."10 11# Check if the health check script exists12if [ ! -f "$HEALTH_SCRIPT" ]; then13    echo "❌ Health check script not found at: $HEALTH_SCRIPT"14    exit 115fi16 17# Make sure the script is executable18chmod +x "$HEALTH_SCRIPT"19 20# Create the cron job entry21CRON_ENTRY="0 1 * * * $HEALTH_SCRIPT"22 23# Check if cron job already exists24if crontab -l 2>/dev/null | grep -q "$HEALTH_SCRIPT"; then25    echo "⚠️  Cron job already exists for health monitoring"26    echo "Current cron jobs:"27    crontab -l | grep "$HEALTH_SCRIPT"28else29    # Add the cron job30    (crontab -l 2>/dev/null; echo "$CRON_ENTRY") | crontab -31    echo "✅ Cron job added successfully!"32    echo "Health check will run every hour at minute 0"33fi34 35echo ""36echo "📋 Current cron jobs:"37crontab -l38 39echo ""40echo "📝 Health check script location: $HEALTH_SCRIPT"41echo "📊 Log file location: /tmp/fastapi_health.log (temporary, cleaned up after each run)"42echo ""43echo "🔍 To view logs during execution: tail -f /tmp/fastapi_health.log"44echo "🗑️  To remove cron job: crontab -e (then delete the line with health_check.sh)"45