IMAT5122 - Computer Systems and Networks: Linux Bash Scripting
VerifiedAdded on 2022/11/17
|13
|2206
|488
Project
AI Summary
This assignment presents a comprehensive Linux Bash scripting project designed to monitor and log system changes. The student's solution begins by defining the Bash directory and utilizes the Shebang to specify the interpreter location. The script, named 'mySysMonitor.sh,' employs various Bash commands such as 'ps' to display running processes, including CPU and RAM usage, 'lsusb -v' to list USB devices, 'df -h' to check disk usage, 'nmcli device status' to display network interface status, and 'cat /root/.bash_history' to monitor user commands. The script's output, including timestamps, is directed to a log file. The report details the installation, commands, and generated outputs, demonstrating a strong understanding of system monitoring and Bash scripting principles. The student also provides a detailed explanation of each command and its usage within the script, along with a conclusion summarizing the accuracy and appropriateness of the chosen commands.

Running Head: LINUX BASH SCRIPTING
LINUX BASH SCRIPTING
Name of the Student:
Name of the University:
Author Note:
LINUX BASH SCRIPTING
Name of the Student:
Name of the University:
Author Note:
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

1LINUX BASH SCRIPTING
Table of Contents
Introduction......................................................................................................................................2
Discussion........................................................................................................................................2
Installation of the script...............................................................................................................2
Commands used in the script.......................................................................................................3
Outputs generated........................................................................................................................5
The command that should be used to execute the bash script.....................................................9
mySysMonitor.sh file..................................................................................................................9
Conclusion.....................................................................................................................................10
Bibliography..................................................................................................................................12
Table of Contents
Introduction......................................................................................................................................2
Discussion........................................................................................................................................2
Installation of the script...............................................................................................................2
Commands used in the script.......................................................................................................3
Outputs generated........................................................................................................................5
The command that should be used to execute the bash script.....................................................9
mySysMonitor.sh file..................................................................................................................9
Conclusion.....................................................................................................................................10
Bibliography..................................................................................................................................12

2LINUX BASH SCRIPTING
Introduction
Bash is another name for the Unix shell. To interact with the operating system or in short
the OS, bash uses a command line interface (CLI). The advantage of using bash script is that the
commands that are used in the command line can be used as a series of commands that execute
all at the same time. Bash scripts helps in executing a series of command. Mac OS and Linux
operating system offers bash by default. Steve Bourne wrote the bash or the Bourne Again Shell.
Bash was first seen in the Seventh Edition Bell Labs Research version of Unix. In this report,
some bash commands are discussed which are used under the shell script named as
“mySysMonitor.sh” and, the explanation for those commands are also provided. In addition, the
output in the log file is also provided in this report.
Discussion
Installation of the script
Firstly, the bash directory is determined for the system in which the script will be written
and executed. In this case, the path is #!/usr/bin/bash. Checking the bash directory before starting
the script is always recommended. By using the command ‘which bash’ in the terminal, the
directory of the bash can be determined. The symbol before the staring of any bash directory #!
is known as Shebang. The function of the Shebang is to direct the script in the location of the
interpreter. The directory that is used after the Shebang is the location to the interpreter, the
location of the interpreter in this case is /usr/bin/bash.
Now, in order to write the script any text editor can be used in the Linux system but, vi
editor is the most basic one. In the beginning of the script, the location of the interpreter is used,
which will be like, #!/usr/bin/bash. The next step is to write the commands that will be used in
Introduction
Bash is another name for the Unix shell. To interact with the operating system or in short
the OS, bash uses a command line interface (CLI). The advantage of using bash script is that the
commands that are used in the command line can be used as a series of commands that execute
all at the same time. Bash scripts helps in executing a series of command. Mac OS and Linux
operating system offers bash by default. Steve Bourne wrote the bash or the Bourne Again Shell.
Bash was first seen in the Seventh Edition Bell Labs Research version of Unix. In this report,
some bash commands are discussed which are used under the shell script named as
“mySysMonitor.sh” and, the explanation for those commands are also provided. In addition, the
output in the log file is also provided in this report.
Discussion
Installation of the script
Firstly, the bash directory is determined for the system in which the script will be written
and executed. In this case, the path is #!/usr/bin/bash. Checking the bash directory before starting
the script is always recommended. By using the command ‘which bash’ in the terminal, the
directory of the bash can be determined. The symbol before the staring of any bash directory #!
is known as Shebang. The function of the Shebang is to direct the script in the location of the
interpreter. The directory that is used after the Shebang is the location to the interpreter, the
location of the interpreter in this case is /usr/bin/bash.
Now, in order to write the script any text editor can be used in the Linux system but, vi
editor is the most basic one. In the beginning of the script, the location of the interpreter is used,
which will be like, #!/usr/bin/bash. The next step is to write the commands that will be used in
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

3LINUX BASH SCRIPTING
the bash script. The file should be saved with the extension of .sh which is the most common file
extension that is used to denote a bash script. The file name that is to be executed is named as
“filename.sh”, the name of the file in this case is “mySysMonitor.sh”.
The next step is the execution of the script. Bash terminal should be used to make the
script executable. In the terminal, ‘chmod +x <filename>’ command is used. In this case, it will
be ‘chmod +x mySysMonitor.sh’. The chmod or “change mode” is a system level command,
which allows a user to manually change the permission for any file. The basic syntax for the
chmod command is: chmod [reference] [operator] [mode] file. For the [reference], four options
are available: u- which is the owner class, g- denotes the group class, o- denotes the others class
and lastly, a- all classes. Three options are available in the [operator]: +, - and =. In order to add
the specified mode to the specified class the ‘+’ operator is used, the ‘–‘ operator is used to
remove the modes, and to specify the exact mode for a specified class the ‘=’ operator is used.
There are three permissions available: r- read the file permission, w- write permission, x- is used
to execute a file or search in the directory.
Once the file is executable the command “./<filename>” is used to run the script. The
command is “./mySysMonitor.sh”, for this case.
Commands used in the script
ps- The common use of ps command is to display all the currently running processes of a system.
Full form of ps is ‘process status’. ps command can also displays the PID (process identification
number).
The ps command is very easy to remember and is a very basic command, which is the
reason behind using this command for this bash script to display the currently running processes.
the bash script. The file should be saved with the extension of .sh which is the most common file
extension that is used to denote a bash script. The file name that is to be executed is named as
“filename.sh”, the name of the file in this case is “mySysMonitor.sh”.
The next step is the execution of the script. Bash terminal should be used to make the
script executable. In the terminal, ‘chmod +x <filename>’ command is used. In this case, it will
be ‘chmod +x mySysMonitor.sh’. The chmod or “change mode” is a system level command,
which allows a user to manually change the permission for any file. The basic syntax for the
chmod command is: chmod [reference] [operator] [mode] file. For the [reference], four options
are available: u- which is the owner class, g- denotes the group class, o- denotes the others class
and lastly, a- all classes. Three options are available in the [operator]: +, - and =. In order to add
the specified mode to the specified class the ‘+’ operator is used, the ‘–‘ operator is used to
remove the modes, and to specify the exact mode for a specified class the ‘=’ operator is used.
There are three permissions available: r- read the file permission, w- write permission, x- is used
to execute a file or search in the directory.
Once the file is executable the command “./<filename>” is used to run the script. The
command is “./mySysMonitor.sh”, for this case.
Commands used in the script
ps- The common use of ps command is to display all the currently running processes of a system.
Full form of ps is ‘process status’. ps command can also displays the PID (process identification
number).
The ps command is very easy to remember and is a very basic command, which is the
reason behind using this command for this bash script to display the currently running processes.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

4LINUX BASH SCRIPTING
The options that are available to use with the ps command are: A- every process is selected, u-
every process present in the terminal is selected along with all other users, x- this option selects
all the processes without controlling the ttys. The usage of the options are as follows: ps –a or ps
–x or ps –u.
echo- This command simply displays a line of string in the terminal.
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -n 6- This is also a use of the ps
command to show the top five CPU and RAM utilizing processes of the system. In the
command, –eo is used in order to select all processes and, ‘o’ sorts the order of the processes. Pid
denotes the process ID and ppid denotes the parent process ID. Cmd column will display all the
commands. The %mem and %cpu will show the percentage memory and the CPU usage for a
process. The --sort=-%mem sorts the order according to the percentage use of the memory
column, from highest to lowest. The head command is used to display the top ten results, but to
display only the top five processes –n 6 is used.
lsusb –v- All the USB devices that are connected to the system are showed using this command.
The lshw command can be another option which can be used to list the system hardware.
In this case, only the USB details that are connected to the system are required. Thus, using lsusb
is a better option.
df –h- To check the disk usage in bash df is an utility command that can be used.. The –h assures
the output generated is in human readable format.
Another command is also available to check the disk usage, which is the du command
but, more details is provided by the df command. So, for this problem the df command is used.
The options that are available to use with the ps command are: A- every process is selected, u-
every process present in the terminal is selected along with all other users, x- this option selects
all the processes without controlling the ttys. The usage of the options are as follows: ps –a or ps
–x or ps –u.
echo- This command simply displays a line of string in the terminal.
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -n 6- This is also a use of the ps
command to show the top five CPU and RAM utilizing processes of the system. In the
command, –eo is used in order to select all processes and, ‘o’ sorts the order of the processes. Pid
denotes the process ID and ppid denotes the parent process ID. Cmd column will display all the
commands. The %mem and %cpu will show the percentage memory and the CPU usage for a
process. The --sort=-%mem sorts the order according to the percentage use of the memory
column, from highest to lowest. The head command is used to display the top ten results, but to
display only the top five processes –n 6 is used.
lsusb –v- All the USB devices that are connected to the system are showed using this command.
The lshw command can be another option which can be used to list the system hardware.
In this case, only the USB details that are connected to the system are required. Thus, using lsusb
is a better option.
df –h- To check the disk usage in bash df is an utility command that can be used.. The –h assures
the output generated is in human readable format.
Another command is also available to check the disk usage, which is the du command
but, more details is provided by the df command. So, for this problem the df command is used.

5LINUX BASH SCRIPTING
nmcli device status- The nmcli command has many functions. This command is mainly used to
control the Network manager and can also display the network device status, the command can
also be used to create or edit and to activate or deactivate or to delete a device. The system status
for the devices can also be displayed using the nmcli command.
cat /root/.bash_history- The cat command stands for “concatenate“. The command can be used
to display the contents of a single file or to view the content of multiple files and this is all done
in the terminal. The cat command can also create a new file. The monitoring of the commands
that are used by the user is done using this command.
NOTE: the /.bash_history is as hidden file in the Linux file system. This file contains all the
commands executed by the user. To see the file, go to the directory where your script is located
and then press Ctrl+H.
Outputs generated
nmcli device status- The nmcli command has many functions. This command is mainly used to
control the Network manager and can also display the network device status, the command can
also be used to create or edit and to activate or deactivate or to delete a device. The system status
for the devices can also be displayed using the nmcli command.
cat /root/.bash_history- The cat command stands for “concatenate“. The command can be used
to display the contents of a single file or to view the content of multiple files and this is all done
in the terminal. The cat command can also create a new file. The monitoring of the commands
that are used by the user is done using this command.
NOTE: the /.bash_history is as hidden file in the Linux file system. This file contains all the
commands executed by the user. To see the file, go to the directory where your script is located
and then press Ctrl+H.
Outputs generated
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

6LINUX BASH SCRIPTING
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

7LINUX BASH SCRIPTING

8LINUX BASH SCRIPTING
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

9LINUX BASH SCRIPTING
The command that should be used to execute the bash script
mySysMonitor.sh file
exec 1>>/root/mySysMonitor.log 2>&1
echo "Time: $(date)." >> /root/mySysMonitor.log
#!/usr/bin/bash
echo "This is the list of all the current processes-->>>>>>>>>>>>>>>>>"
ps
echo "************************************************"
echo "This shows the list of top 5 CPU and RAM utilizing processes->>>>>>>>>>>>>>"
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -n 6
echo "*************************************************"
The command that should be used to execute the bash script
mySysMonitor.sh file
exec 1>>/root/mySysMonitor.log 2>&1
echo "Time: $(date)." >> /root/mySysMonitor.log
#!/usr/bin/bash
echo "This is the list of all the current processes-->>>>>>>>>>>>>>>>>"
ps
echo "************************************************"
echo "This shows the list of top 5 CPU and RAM utilizing processes->>>>>>>>>>>>>>"
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -n 6
echo "*************************************************"
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

10LINUX BASH SCRIPTING
echo "The list of all the plugged devices and their full details->>>>>>>>>>>>>>>>"
lsusb -v
echo "**************************************************"
echo "Disk Usage->>>>>>>>>>>>>>>>>>>>"
df -h
echo "***************************************************"
echo "List of the network interfaces and their states->>>>>>>>>>>>>>>>>>>>"
nmcli device status
echo "****************************************************"
echo "List of commands that are used by the user or the monitoring of commands used-
>>>>>>>>>>>>>>>>>>>"
cat /root/.bash_history
echo "*****************************************************"
echo "*************************************(End of
List)*********************************************"
Conclusion
Every command used in the script are accurate, short and are easy to remember.
According to the requirements, the commands used are the most appropriate ones. All the
necessary tests were done while doing the assignment and the script executes properly by
echo "The list of all the plugged devices and their full details->>>>>>>>>>>>>>>>"
lsusb -v
echo "**************************************************"
echo "Disk Usage->>>>>>>>>>>>>>>>>>>>"
df -h
echo "***************************************************"
echo "List of the network interfaces and their states->>>>>>>>>>>>>>>>>>>>"
nmcli device status
echo "****************************************************"
echo "List of commands that are used by the user or the monitoring of commands used-
>>>>>>>>>>>>>>>>>>>"
cat /root/.bash_history
echo "*****************************************************"
echo "*************************************(End of
List)*********************************************"
Conclusion
Every command used in the script are accurate, short and are easy to remember.
According to the requirements, the commands used are the most appropriate ones. All the
necessary tests were done while doing the assignment and the script executes properly by

11LINUX BASH SCRIPTING
generating the log file that captures every output that is being generated in the terminal. The time
stamp to the log file were also added.
generating the log file that captures every output that is being generated in the terminal. The time
stamp to the log file were also added.
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 13
Related Documents
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.





