Shell Scripting mini project.

Shell Scripting mini project.

View Linux System details using shell scripting.

Hi, I have written a shell script to view information like free space, disk space, date etc. of a Linux system. I started an Instance on EC2 AWS and made this script using bash.

What will Shell Script perform?

  1. Welcome the user.

  2. Show the Date and Time.

  3. Show the uptime of the server and the last logins.

  4. Show the disk space and RAM utilization.

  5. Show the top processes.

You can add further instructions/commands according to your needs.

Commands used?

CommandsUse
$whoamiused to display the current user.
$dateused to display the date.
$uptimeused to find out how long the system is active (running).
$headused to print a particular number of lines of script based on argument.
$lastused to find the last login details.
$df -hused to get details about the disk space of the Linux System.
$freeused to get details about RAM.
$topused to show which processes are consuming processor and memory resources.
$echoused to display lines of text or string passed as argument.

Display Date and Time:

Output for echo -e "Current Date and Time is: $(date)"

Checking uptime and last login details:

Commands used - $echo, $uptime, $head, $last (-a flag is used with $last to display the hostname in the last column).

Output for echo -e "The uptime of the server is: $(uptime) Last login details: $(last -a | head -3)"

Checking Disc Space:

5.4G(11th arg) is available out of the total size of 7.6G*(9th arg)*.

  • Disc space available is $11 / $9 ( $(number) represents which argument we are using).

Output for $(df -h)

Output for $(df -h | xargs | awk '{print $11"/"$9}')

Checking CPU utilization:

commands used - $echo, $top, $head

Output for echo -e "Top CPU processes: $(top | head -10)"

Script:

Output:


Let's connect!

LinkedIn

Github

Instagram