Shell Scripting | Topic "Basic System Info Bash Script"



Please Read This 👇🏾

 


In previous post we had seen that how to create a very basic "Hello World" bash script. To continue our shell script tutorial , In this post we will see some more simple bash scripts which will help you to understand the some more basic concepts of bash shell scripts.


Now we will create a bash script to get details about some basic information about our system.





Script Explanation:

a) I am skipping the first five lines explanation as I have already explained these things.

b) echo "********************************************************************"

This simple echo command, which will print the asterisks(*) in the output. We are using this echo to make our output more visible & clean.

c) echo -e "\nThis Simple Bash Script Will Display Basic System Information\n"

This echo command will print the message typed between quotes (""), here -e means expression which we have used for /n means print the message in new line.


d) echo -e "\nNo.1:\nCurrent Time & Date is:`date`\n"

This echo command including many things. First it will display the No.1: in separate line. Then it display the message Current Time & Date is:. Then it run the date  command.
                       
Note that if you want to run a command inside the echo command just put tick(``) sign arround it. As we did in this echo command. 

e) echo -e "\nNo.2:\nCurrent User Name is: `whoami`\n"  

Here we are executing whoami command inside the echo command

f) echo -e "\nNo.3:\nSystem Hostname is:`hostname`\n"
Here we are executing hostname command inside the echo command
g) echo -e "\nNo.4:\nOS Type is:`uname -o`\nKernel Name is:`uname -s`\nSystem Architecture is:`uname -i`"

Note that here we are executing three commands inside the echo command. All are starts with uname

h) echo -e "\nNo.5:\nCurrently Login Sessions are:\n`w -i`\n"

Here we are executing w -i command inside the echo command. just try to run this command in terminal.

i) echo -e "\nNo.6:\nMounted Partition Information:\n`df -h`\n"

 Here we are executing df -h command inside the echo command.

j) Save this script with .sh extension & give the execute permissions to this file

Output
 


So this is our very simple script , in  which we learn about how to use echo command to print output in new line also we learn that how to run a command inside the echo command.If you have any question , please let me know.

Try your self by creating a simple script using simple commands.

Sharing is Caring

Previous                                                                                                                                             Next

Post a Comment

0 Comments