#!/bin/bash
# Define the log file directory
log_file_dir="/path/to/log/files"
# Define the HTML file name and header
html_file="log_file_validation.html"
html_header="<html><head><title>Log File Validation Report</title></head><body>"
html_footer="</body></html>"
# Define the recipient email address
recipient_email="recipient@example.com"
# Initialize the HTML file
echo "$html_header" > "$html_file"
# Validate the log files
echo "<h2>Log File Validation Report</h2>" >> "$html_file"
echo "<table border='1'>" >> "$html_file"
echo "<tr><th>File Name</th><th>Result</th></tr>" >> "$html_file"
for log_file in "$log_file_dir"/*.log; do
if [ -f "$log_file" ]; then
log_file_size=$(wc -c "$log_file" | awk '{print $1}')
if [ "$log_file_size" -gt 0 ]; then
validate_result="Success"
else
validate_result="Failed"
fi
else
validate_result="Failed"
fi
echo "<tr><td>$log_file</td><td>$validate_result</td></tr>" >> "$html_file"
done
echo "</table>" >> "$html_file"
# Add the HTML file footer
echo "$html_footer" >> "$html_file"
# Send the HTML file as an email attachment
mail -s "Log File Validation Report" -a "$html_file" "$recipient_email" <<EOF
Please find the attached log file validation report.
EOF
No comments:
Post a Comment