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?
Welcome the user.
Show the Date and Time.
Show the uptime of the server and the last logins.
Show the disk space and RAM utilization.
Show the top processes.
You can add further instructions/commands according to your needs.
Commands used?
Commands | Use |
$whoami | used to display the current user. |
$date | used to display the date. |
$uptime | used to find out how long the system is active (running). |
$head | used to print a particular number of lines of script based on argument. |
$last | used to find the last login details. |
$df -h | used to get details about the disk space of the Linux System. |
$free | used to get details about RAM. |
$top | used to show which processes are consuming processor and memory resources. |
$echo | used 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)"