#!/bin/ksh
# Output HTML file
OUTPUT_FILE="server_log_ksh.html"
# Start HTML content
cat <<EOL > $OUTPUT_FILE
<html>
<head>
<meta charset="UTF-8">
<title>Server CLI Commands Log</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 8px;
}
th {
background-color: #4dc3ff;
}
td.fail {
background-color: #ff5733;
}
td.pass {
background-color: #4cff33;
}
td.warning {
background-color: yellow;
}
.content-section {
margin-top: 20px;
padding: 10px;
border: 1px solid #ccc;
position: relative;
}
.top-link {
position: fixed;
bottom: 20px;
right: 20px;
background-color: #4dc3ff;
padding: 10px;
border-radius: 5px;
color: black;
text-decoration: none;
z-index: 1000;
}
.top-link:hover {
background-color: #3a9cd9;
}
</style>
<script>
function checkScroll() {
var topLink = document.getElementById('top-link');
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
topLink.style.display = 'block';
} else {
topLink.style.display = 'none';
}
}
window.onload = checkScroll;
window.onscroll = checkScroll;
</script>
</head>
<body>
<div id="top"></div>
<a href='#top' id='top-link' class='top-link' style='display: none;'>Go to top รข†‘</a>
<h2>Server CLI Commands Log</h2>
<table>
<tr><th>#</th><th>Command</th><th>Output</th></tr>
EOL
# List of commands to show directly in table (short commands)
set -A direct_commands "uptime" "whoami" "ls -l /root"
# List of commands to show as links (long output commands)
set -A link_commands "cat /etc/resolv.conf" "cat ~/.zsh_history" "ps -ef" "netstat -an" "df -h" "uname -a"
# Execute direct commands and log results
index=1
for cmd in "${direct_commands[@]}"; do
print "Running: $cmd"
output=$(eval "$cmd" 2>&1)
exit_code=$?
# Add to table
print "<tr><td>$index</td><td><pre>$cmd</pre></td><td><pre>$output</pre></td></tr>" >> $OUTPUT_FILE
let index=index+1
done
# Add link commands to table
for cmd in "${link_commands[@]}"; do
print "Running: $cmd"
output=$(eval "$cmd" 2>&1)
exit_code=$?
# Add to table with link
print "<tr><td>$index</td><td><pre>$cmd</pre></td><td><a href='#content_${index}'>Click to view</a></td></tr>" >> $OUTPUT_FILE
let index=index+1
done
# Close the table
print "</table>" >> $OUTPUT_FILE
# Add content sections for link commands
index=1
for cmd in "${direct_commands[@]}" "${link_commands[@]}"; do
if [[ $cmd == cat* ]] || [[ $cmd == ps* ]] || [[ $cmd == netstat* ]] || [[ $cmd == df* ]] || [[ $cmd == uname* ]]; then
output=$(eval "$cmd" 2>&1)
print "<div class='content-section' id='content_${index}'>" >> $OUTPUT_FILE
print "<h3>Output of: $cmd</h3>" >> $OUTPUT_FILE
print "<pre>$output</pre>" >> $OUTPUT_FILE
print "</div>" >> $OUTPUT_FILE
fi
let index=index+1
done
# Close HTML tags
cat <<EOL >> $OUTPUT_FILE
</body>
</html>
EOL
print "Log saved to $OUTPUT_FILE"