#!/bin/bash # Monitor Check-in Setup Script # This script sets up automated URL check-ins with systemd set -e # Exit on error # Check if running as root if [[ $EUID -ne 0 ]]; then echo "Error: This script must be run as root" echo "Please run with: sudo $0" exit 1 fi echo "==========================================" echo "Monitor Check-in Setup Script" echo "==========================================" echo "" # Prompt for endpoint URL read -p "Enter the endpoint URL (e.g., https://example.com/your-endpoint): " endpoint_url # Validate URL format if [[ ! "$endpoint_url" =~ ^https?:// ]]; then echo "Error: URL must start with http:// or https://" exit 1 fi # Create the monitor script echo "Creating monitor script at /opt/monitor_checkin.sh..." tee /opt/monitor_checkin.sh > /dev/null < /dev/null 2>&1; do echo "Network not ready, waiting..." sleep 5 done echo "Network is ready. Script started. Calling URL every 55 seconds..." while true; do curl -s "\$url" > /dev/null echo "Called \$url at \$(date '+%Y-%m-%d %H:%M:%S')" >> /var/log/call-url.log sleep \$interval done EOF # Make the script executable echo "Making script executable..." chmod +x /opt/monitor_checkin.sh # Create the systemd service echo "Creating systemd service..." tee /etc/systemd/system/monitor_checkin.service > /dev/null <