Shell script to perform a Health Check of the Linux Server


In this post, I am sharing a shell script which will create a HTML output for a Linux OEL server health check.


You can change and Modify as per your needs. The script will generate a file named as server_health_report.html


[root@standby ~]# ls -ltr
total 8
-rw-r--r--. 1 root root 1177 Jun 22 04:25 health.sh
-rw-r--r--. 1 root root 3262 Jun 22 04:25 server_health_report.html

Script:

#!/bin/bash

# Output file for the health check report
OUTPUT_FILE="server_health_report.html"

# Function to generate formatted HTML report
generate_report() {
  echo "<html>
  <head>
    <title>Server Health Check Report</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        margin: 20px;
      }
      h1, h2, h3 {
        color: #333;
      }
      table {
        border-collapse: collapse;
        width: 100%;
      }
      th, td {
        padding: 8px;
        text-align: left;
        border-bottom: 1px solid #ddd;
      }
    </style>
  </head>
  <body>
    <h1>Server Health Check Report</h1>
    <h2>Date: $(date)</h2>

    <h3>System Information</h3>
    <table>
      <tr><th>Hostname</th><td>$(hostname)</td></tr>
      <tr><th>Kernel Version</th><td>$(uname -r)</td></tr>
      <tr><th>Uptime</th><td>$(uptime -p)</td></tr>
    </table>

    <h3>CPU Information</h3>
    <pre>$(lscpu)</pre>

    <h3>Memory Information</h3>
    <pre>$(free -h)</pre>

    <h3>Disk Usage</h3>
    <pre>$(df -h)</pre>
  </body>
  </html>" >"$OUTPUT_FILE"

  echo "Server health check report generated: $OUTPUT_FILE"
}

# Main script
generate_report


Output Format Screenshot:








If you like please follow and comment