├── LICENSE
├── README.md
├── Server-Health-Report-shashank-dbserver-170306-0828.html
└── syshealth.sh
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Shashank Srivastava
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Linux Server HTML Health Report (Using Shell Script)
2 | A shell script to generate Linux Server's health report in HTML
3 |
4 | ## Introduction
5 | SysAdmins continuoulsly need to monitor their infrastructure & while, there are numerous [Monitoring Tools](https://watilearnd2day.wordpress.com/category/server-monitoring/) available for Linux to achieve this, nothing beats the simiplicity of an HTML Report that you can generate either by executing a shell script or by tucking it inside a CRON job. My script does exactly that.
6 |
7 | ## How to use?
8 | Just download the script & make it executable using ``chmod +x syshealth.sh``. Now you can either execute it using ``sudo ./syshealth.sh`` or put it inside a CRON job.
9 |
10 | ## Video (Script in action)
11 | Watch [this video](https://www.youtube.com/watch?v=tgnlo5_T6XU) to see the script in action.
12 |
13 | ## Additional notes
14 | This script also explains (*I mean, along-with having the script to perform the intended tasks, this script also serves to demonstrate how tags can be used*) how HTML tags can be used inside a shell script. You can modify it to suit your needs.
15 | You must run this script as root so as to see full disk-usage details. Normal user can't see other home-directories & hence ``du -sh`` won't return accurate details if run as non-root.
16 | To see what the output HTML file looks like, please see the HTML file packaged in this repository.
17 |
--------------------------------------------------------------------------------
/Server-Health-Report-shashank-dbserver-170306-0828.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
OS Details :
14 |
15 |
16 |
17 |
OS Name
18 |
IP Address
19 |
Uptime
20 |
21 |
22 |
23 |
24 |
Ubuntu
25 |
192.168.0.51
26 |
21:42
27 |
28 |
29 |
30 |
Resources Utilization :
31 |
32 |
33 |
34 |
35 |
# of Processes
36 |
Root FS Usage
37 |
Total Size of Root FS
38 |
Load Average
39 |
Used RAM(in MB)
40 |
Total RAM(in MB)
41 |
iNode Status
42 |
43 |
44 |
45 |
46 |
263
47 |
40%
48 |
56G
49 |
0,29, 0,22, 0,13
50 |
1895
51 |
2000
52 |
32%
53 |
54 |
55 |
56 |
Culprit Directories(Eating up disk space) :
57 |
58 |
59 |
60 |
61 |
Size
62 |
Name
63 |
64 |
65 |
66 |
1,2G
67 |
/home/shashank/xld
68 |
69 |
70 |
1,2G
71 |
/home/shashank/Downloads
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/syshealth.sh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 | #Author : - Shashank Srivastava
3 | #Date : - 6 March, 2017
4 |
5 | #Checking if this script is being executed as ROOT. For maintaining proper directory structure, this script must be run from a root user.
6 | if [ $EUID != 0 ]
7 | then
8 | echo "Please run this script as root so as to see all details! Better run with sudo."
9 | exit 1
10 | fi
11 | #Declaring variables
12 | #set -x
13 | os_name=`uname -v | awk {'print$1'} | cut -f2 -d'-'`
14 | upt=`uptime | awk {'print$3'} | cut -f1 -d','`
15 | ip_add=`ifconfig | grep "inet addr" | head -2 | tail -1 | awk {'print$2'} | cut -f2 -d:`
16 | num_proc=`ps -ef | wc -l`
17 | root_fs_pc=`df -h /dev/sda1 | tail -1 | awk '{print$5}'`
18 | total_root_size=`df -h /dev/sda1 | tail -1 | awk '{print$2}'`
19 | #load_avg=`uptime | cut -f5 -d':'`
20 | load_avg=`cat /proc/loadavg | awk {'print$1,$2,$3'}`
21 | ram_usage=`free -m | head -2 | tail -1 | awk {'print$3'}`
22 | ram_total=`free -m | head -2 | tail -1 | awk {'print$2'}`
23 | inode=`df -i / | head -2 | tail -1 | awk {'print$5'}`
24 | os_version=`uname -v | cut -f2 -d'~' | awk {'print$1'} | cut -f1 -d'-' | cut -c 1-5`
25 | #Creating a directory if it doesn't exist to store reports first, for easy maintenance.
26 | if [ ! -d ${HOME}/health_reports ]
27 | then
28 | mkdir ${HOME}/health_reports
29 | fi
30 | html="${HOME}/health_reports/Server-Health-Report-`hostname`-`date +%y%m%d`-`date +%H%M`.html"
31 | email_add="change this to yours"
32 | for i in `ls /home`; do sudo du -sh /home/$i/* | sort -nr | grep G; done > /tmp/dir.txt
33 | #Generating HTML file
34 | echo "" >> $html
35 | echo "" >> $html
36 | echo "" >> $html
37 | echo "" >> $html
38 | echo "" >> $html
44 | echo " " >> $html
45 | echo "
" >> $html
109 | echo "" >> $html
110 | echo "" >> $html
111 | echo "Report has been generated in ${HOME}/health_reports with file-name = $html. Report has also been sent to $email_add."
112 | #Sending Email to the user
113 | cat $html | mail -s "`hostname` - Daily System Health Report" -a "MIME-Version: 1.0" -a "Content-Type: text/html" -a "From: Shashank Srivastava " $email_add
114 |
--------------------------------------------------------------------------------