#!/bin/bash set -x # Directory to generate index.html for TARGET_DIR="/var/www/imonitorg.com/public_html/customerplots/rtcustomerplots" OUTPUT_FILE="$TARGET_DIR/index.html" # Start the HTML file cat < "$OUTPUT_FILE" Index of $(basename "$TARGET_DIR")

Index of $(basename "$TARGET_DIR")

EOF # Recursive function to process directories generate_index() { local dir="$1" local relative_path="$2" # Path to append to links for item in "$dir"/*; do if [ -e "$item" ]; then name=$(basename "$item") date=$(stat -c '%y' "$item" | cut -d'.' -f1) # Get last modified date if [ -d "$item" ]; then # Add a row for the directory echo " " >> "$OUTPUT_FILE" # Recursively process subdirectories generate_index "$item" "$relative_path$name/" else # Add a row for the file echo " " >> "$OUTPUT_FILE" fi fi done } # Generate index for the root directory generate_index "$TARGET_DIR" "" # End the HTML file cat <> "$OUTPUT_FILE"
Name Last Modified
$name/$date
$name$date
EOF