#!/bin/bash # Directory to generate index.html for #set -x 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 with indentation generate_index() { local dir="$1" local relative_path="$2" local depth="$3" # Indentation depth for item in "$dir"/*; do if [ -e "$item" ]; then name=$(basename "$item") date=$(stat -c '%y' "$item" | cut -d'.' -f1) # Get last modified date indent=$(printf '%*s' $((depth * 4)) '') # Create spaces for indentation if [ -d "$item" ]; then # Add a row for the directory echo " " >> "$OUTPUT_FILE" # Recursively process subdirectories with increased depth generate_index "$item" "$relative_path$name/" $((depth + 1)) else # Add a row for the file echo " " >> "$OUTPUT_FILE" fi fi done } # Generate index for the root directory with initial depth 0 generate_index "$TARGET_DIR" "" 0 # End the HTML file cat <> "$OUTPUT_FILE"
Name Last Modified
$indent$name/$date
$indent$name$date
EOF