Mini Project on Shell Scripting

Mini Project on Shell Scripting

·

2 min read

In this project, we will be creating a shell script that welcomes the logged in user and will display a certain set of information.

The below table contains the list of displayed information and the necessary Linux command for the same:

UsecaseCommand
display any information on screenecho
get current userwhoami
get datedate
information about how long the system has been runninguptime
information about user logins and system rebootslast
information about the system's memory usage in a human-readable formatfree -h
information about disk space usage in a human-readable formatdf -h
top CPU processes runningtop
  1. Create a file with the extension .sh with the below contents

     ubuntu@ip-10-0-0-219:~$ vim shell_script.sh
    
  2. Write the shell script to display the required information

     #!/bin/bash
     echo -e "...................................HELLO..................................................."
     echo -e "Hi $(whoami)!Welcome to my DevOps journey!"
     echo -e "..........................................................................................."
     #show the date and time
     echo -e "Current date and time is: $(date)"
     echo -e "____________________________________________________________________________________________"
     #show uptime and downtime
     echo -e "Uptime of the server is $(uptime) \n Last login details: \n$(last -a | head -3)"
     echo -e "______________________________________________________________________________________________"
     #show disc space and ram utilization
     echo -e "Disc space is $(df -h | xargs | awk '{ print $11 "/" $9 }')"
     echo -e "________________________________________________________________________________________________"
     #show RAM utilization
     echo -e "RAM utilization is $(free | xargs | awk '{print $8 "/" $10}')"
     echo -e "_________________________________________________________________________________________________"
     #show top CPU processes
     echo -e "\nTop CPU processes\n$(top -b -n 1 | tail -n +8 | head -n 10)"
    
  3. Make the file executable with the chmod command

     ubuntu@ip-10-0-0-219:~$ chmod 777 shell_script.sh
    
  4. Run the shell script

     ubuntu@ip-10-0-0-219:~$ ./shell_script.sh
    
  5. The ouput for the above script will be as follows:

Thanks for reading my blog.