Introduction to Linux - A Hands on Guide | Linux Bible | Linux From Scratch | A Newbie's Getting Started Guide to Linux | Linux Command Line Cheat Sheet | More Linux eBooks



Thursday, 7 November 2013

A Simple BASH Script to Display the System Information


Let us create a simple BASH script that provides information regarding your Linux system which includes:

  • Active Users
  • Uptime
  • Load average
  • Free and Used Memory
  • Disk Space Utilization
This script runs commands like w, uname, uptime, free and df. One can modify the script a bit accordingly in order to get the system information from multiple servers.

Script:


#!/bin/bash

clear

echo “This information is brought to you by $0.”

#Welcome the user
echo “Welcome, $USER”
echo
echo “Today is `date`.”
echo

#Currently active users.
echo “Following users are presently active:”
w | cut -d ' ' -f 1 | grep -v USER | sort -u
echo

#System information using uname command
echo “This is `uname -s` running on a `uname -m` processor.”
echo

#Information of uptime
echo “Following is the uptime information:”
uptime
echo

#Showing free memory
echo “Memory Details:”
free
echo

#Disk space usage using df command
echo “Disk Space Utilization:”
df -mh
echo 


That's it! If you can add something to above script, mention it in the comments so that I can update above script to make it more powerful.

More BASH Scripts:

0 comments:

Post a Comment