Shell Scripting Mini Project  Server Status Monitor

Shell Scripting Mini Project Server Status Monitor

Creating a shell script that will show the server status statics

Table of contents

Introduction:

In this mini-project, we have created a simple shell script that provides essential information about the server's status. The script is designed to offer an all-in-one solution to retrieve important server details without the need for a graphical user interface (GUI).

Keywords: Shell Scripting, Server Status, Command Line, Terminal, Disk Space, RAM Utilization, CPU Processes

Hey there, welcome to our Server Status Monitor!

Objective: The main objective of this mini-project is to provide a quick overview of your server's vital statistics without the need for a GUI or navigating through different commands.

Let's see what this script can do for you:

  1. Greetings and Date/Time: Upon running the script, it will greet you with a warm welcome, addressing you by your username. Then, it will display the current date and time for your convenience.

Keywords: Greetings, Date, Time

  1. Server Disk Utilization: Next, the script will present the disk utilization percentage of your server, giving you insights into how much disk space is being used.

Keywords: Disk Utilization, Storage, Disk Space, Percentage

  1. Memory Utilization: The script will also showcase the percentage of RAM utilization, allowing you to monitor the memory usage of your server.

Keywords: Memory Utilization, RAM, Percentage

  1. Uptime and Users: Additionally, the script will provide details about the server's uptime, including the duration it has been running, and the number of users currently logged in.

Keywords: Uptime, Users, Server Duration

  1. Top CPU Processes: Finally, the script will display the top CPU processes running on your server, giving you an idea of the most resource-intensive tasks.

Keywords: CPU Processes, Resource Usage, Top Processes


To run t

let's see what is our actual output of the screen

here is some basic commands to get idea of things to find form terminal

#To display the current user we use the $whoami command

#command which shows the date and time $date

#uptime is used to find out how long the system is active (running) $uptime

#to find last login details $last if we want the first no.of details then we can use $head

#memory command which gives details about disk space is $df -H

#memory command which gives details about RAM is $free

#!/bin/bash

echo "*****************SERVER**STATUS***********************"
echo "Welcome $(whoami)                    "
echo "Date : $(date | awk '{print $2"-"$3"-"$4}')        Time : $(date | awk '{print $5"-"$6"-"$7}') ";
echo "-------------------------------------------------------"
echo "Server Disk Utilization $( df -h | xargs | awk '{rounded = sprintf("%.2f", ($16 / $15) * 100); print rounded}') % "
echo "Total Disk : $( df -h | xargs | awk '{print $15}')B, Used : $( df -h | xargs | awk '{print $16}')B, Left : $( df -h | xargs | awk '{print $17}')B"
echo "-------------------------------------------------------"
echo "Memory utilization percentage $(free | xargs | awk '{rounded = sprintf("%.2f", ($9/$8)*100); print rounded}') %"
echo "Total Disk : $(free | xargs | awk '{print $8}'), Used : $(free | xargs | awk '{print $9}'), Left : $(free | xargs | awk '{print $10}')"
echo "-------------------------------------------------------"
echo "Uptime       : $(uptime | xargs | awk '{print $3" "$4}')"
echo "Total User   : $(uptime | xargs | awk '{print $5" "$6}')"
echo "Average Load : $(uptime | xargs | awk '{print $9" "$10" "$11}')"
echo "------------------------------------------------------"
echo "       Top CPU Proccess                              "
echo "$(top | head -10)"
echo "------------------------------------------------------"

To run this script on your server, follow these steps:

  1. Create a new file using a text editor, e.g., "server_status.sh".

  2. Copy the provided script into the file.

  3. Save the file.

  4. Open your terminal and navigate to the directory where the file is saved.

  5. Grant execute permission to the script using the following command:

     bashCopy codechmod +x server_status.sh
    
  6. Execute the script:

     bashCopy code./server_status.sh
    

That's it! You will now have a clear and concise overview of your server's status at your fingertips.

Feel free to customize and enhance the script as per your requirements.

Happy server monitoring!

#ShellScripting #ServerStatus #TerminalCommands #SysAdmin #TechProject