Script for Checking Server Stats.
Skyie
May 29 2017

0  1K+ {{tagitem.name}}
In this tutorial i will be showing you guys, How to view your server infromation and to check your server Stats.

Checking the server/shell utilization is one of the important task, and a good user is the one who knows how to automate his day to day task. Below is the script that will give many such information about your server/shell.





1. Create a new file named "SystemStats.sh". (Create a new bash filed called "SystemStats.sh" in your directory)

> SystemStats.sh


2. Edit the file "SystemStats.sh". (Now edit the file using your favourite editor, In this tutorial we will be using Nano Editor)

nano SystemStats.sh


3. Add the following Script to "SystemStats.sh" (Now we will add the script to the text file through nano editor. Copy/Paste the following script down below to the SystemStats.sh file.)

# ----------------------------------------------------------------------------------------------------------

#!/bin/bash
echo "System Stats"
date;
echo "--------------------------------------------------------------------"
echo "Uptime:"
uptime
echo "--------------------------------------------------------------------"
echo "Currently connected:"
w
echo "--------------------------------------------------------------------"
echo "Last logins:"
last -a |head -3
echo "--------------------------------------------------------------------"
echo "Disk and memory usage:"
df -h | xargs | awk '{print "Free/total disk: " $11 " / " $9}'
free -m | xargs | awk '{print "Free/total memory: " $17 " / " $8 " MB"}'
echo "--------------------------------------------------------------------"
start_log=`head -1 /var/log/messages |cut -c 1-12`
oom=`grep -ci kill /var/log/messages`
echo -n "OOM errors since $start_log :" $oom
echo ""
echo "--------------------------------------------------------------------"
echo "Utilization and most expensive processes:"
top -b |head -3
echo
top -b |head -10 |tail -4
echo "--------------------------------------------------------------------"
echo "Open TCP ports (Recommended To Enable But May Cause Flood):"
# netstat --listen
echo "--------------------------------------------------------------------"
echo "Current connections:"
ss -s
echo "--------------------------------------------------------------------"
echo "processes:"
ps auxf --width=200
echo "--------------------------------------------------------------------"
echo "vmstat:"
vmstat 1 5

# ----------------------------------------------------------------------------------------------------------

4. Save the script to the file. (Now save the script to the file and exit from the editor)

CTRL+X (Hold Control Key and Press X)


5. Change the files access permissions to 755. (Now change the file access mode to 755, We use the command chmod to change/revoke a files permissions)

chmod 755 SystemStats.sh


6. Add an Alias. (Now add Alias to the Execute command which is "./SystemStats.sh" for ease of use)

alias sss='./SystemStats.sh'


7. Execute the Command "sss". (Now execute the Alias command we have created for "./SystemStats.sh" which is "sss")

sss




Optional: Add some colors to your script to make it look better and nicer. Checkout my previous turoial on Color Codes/Tags for Bash for help.



Have Doubts/Questions? Please comment down below on the post or email me at BLinuxYT[at]outlook.com

@Black Linux/Skyie/AutoBotIRC - Buuuuurp Geeky!

Please Login or Sign Up to leave a reply.