├── 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 |
6 |
7 |

Linux Server Report 8 |

Script authored by Shashank Srivastava

9 |
10 |
11 |
12 |
13 |

OS Details :

14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
OS NameIP AddressUptime
Ubuntu192.168.0.5121:42
30 |

Resources Utilization :

31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
# of ProcessesRoot FS UsageTotal Size of Root FSLoad AverageUsed RAM(in MB)Total RAM(in MB)iNode Status
263
40%
56G
0,29, 0,22, 0,13
1895
2000
32%
56 |

Culprit Directories(Eating up disk space) :

57 |
58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |
SizeName
1,2G/home/shashank/xld
1,2G/home/shashank/Downloads
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 39 | echo "
" >> $html 40 | echo "

Linux Server Report" >> $html 41 | echo "

Script authored by Shashank Srivastava

" >> $html 42 | echo "
" >> $html 43 | echo "
" >> $html 44 | echo "
" >> $html 45 | echo "
" >> $html 46 | echo "

OS Details :

" >> $html 47 | echo "" >> $html 48 | echo "" >> $html 49 | echo "" >> $html 50 | echo "" >> $html 51 | echo "" >> $html 52 | echo "" >> $html 53 | echo "" >> $html 54 | echo "" >> $html 55 | echo "" >> $html 56 | echo "" >> $html 57 | echo "" >> $html 58 | echo "" >> $html 59 | echo "" >> $html 60 | echo "" >> $html 61 | echo "" >> $html 62 | echo "" >> $html 63 | echo "" >> $html 64 | echo "
OS NameOS VersionIP AddressUptime
$os_name$os_version$ip_add$upt
" >> $html 65 | echo "

Resources Utilization :

" >> $html 66 | echo "
" >> $html 67 | echo "" >> $html 68 | echo "" >> $html 69 | echo "" >> $html 70 | echo "" >> $html 71 | echo "" >> $html 72 | echo "" >> $html 73 | echo "" >> $html 74 | echo "" >> $html 75 | echo "" >> $html 76 | echo "" >> $html 77 | echo "" >> $html 78 | echo "" >> $html 79 | echo "" >> $html 80 | echo "" >> $html 81 | echo "" >> $html 82 | echo "" >> $html 83 | echo "" >> $html 84 | echo "" >> $html 85 | echo "" >> $html 86 | echo "" >> $html 87 | echo "" >> $html 88 | echo "" >> $html 89 | echo "" >> $html 90 | echo "
# of ProcessesRoot FS UsageTotal Size of Root FSLoad AverageUsed RAM(in MB)Total RAM(in MB)iNode Status
$num_proc
$root_fs_pc
$total_root_size
$load_avg
$ram_usage
$ram_total
$inode
" >> $html 91 | echo "

Culprit Directories(Eating up disk space) :

" >> $html 92 | echo "
" >> $html 93 | echo "" >> $html 94 | echo "" >> $html 95 | echo "" >> $html 96 | echo "" >> $html 97 | echo "" >> $html 98 | echo "" >> $html 99 | echo "" >> $html 100 | echo "" >> $html 101 | while read size name; 102 | do 103 | echo "" >> $html 104 | echo "" >> $html 105 | echo "" >> $html 106 | echo "" >> $html 107 | done < /tmp/dir.txt 108 | echo "
SizeName
$size$name
" >> $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 | --------------------------------------------------------------------------------