#!/usr/bin/python3.12 # Or use #!/usr/bin/python3.9 if you prefer Python 3.9 import datetime import os # --- Configuration (VERY IMPORTANT: Customize this section) --- # 1. Replace 'yourusername.helioho.net' below with YOUR EXACT DOMAIN part # from the full path you found (e.g., 'yourcustomdomain.com'). # It's the part right before '/httpdocs' YOUR_DOMAIN_PART = "tigersak.helioho.st" # <--- ***UPDATE THIS LINE!*** YOUR_DOMAIN_PATH_ROOT = os.path.join("/var/www", "vhosts", YOUR_DOMAIN_PART) # This is where your script and its log file will be located on the server # It will be inside your httpdocs folder, in a new folder called 'my_cron_app' SCRIPT_FOLDER = os.path.join(YOUR_DOMAIN_PATH_ROOT, "httpdocs", "my_cron_app") LOG_FILE_PATH = os.path.join(SCRIPT_FOLDER, "app_activity.log") # --- Ensure the script folder exists (good practice for background apps) --- # This line creates the 'my_cron_app' folder if it doesn't already exist. # It's good to have this in a background script in case you delete the folder by accident. os.makedirs(SCRIPT_FOLDER, exist_ok=True) # --- Main script logic --- try: current_time = datetime.datetime.now() # Adding the current time zone (EEST) as it's relevant to your location. message = f"[{current_time} EEST] My background Python app ran successfully! (Tommy Server)\n" # Print to standard output (this will be captured by the cron job's log file) print(message.strip()) # Write the message to our custom log file with open(LOG_FILE_PATH, "a") as f: # 'a' means append (add to the end of the file) f.write(message) except Exception as e: # If any error happens, log it to the same file error_message = f"[{datetime.datetime.now()} EEST] ERROR: My background app failed: {e}\n" print(error_message.strip()) with open(LOG_FILE_PATH, "a") as f: f.write(error_message)