System Monitoring
System Monitoring
Prerequisites:
Installation:
● Save the Script: Save the script content as system_monitor.sh. You can use a text editor
of your choice.
● Make it Executable: Open a terminal window and navigate to the directory where you
saved the script using the cd command. Then, grant the script execution permission
using the following command:
chmod +x system_monitor.sh
Usage:
Run the Script: Execute the script from the terminal with the following command:
./system_monitor.sh
This will run the script with the default log level (standard).
Specify a Log Level (Optional): The script supports four log levels: verbose, debug, standard,
and key-details. You can specify a desired log level when running the script using the following
syntax:
./system_monitor.sh -l <log_level>
Replace <log_level> with your preferred level (verbose, debug, standard, or key-details). For
example:
./system_monitor.sh -l debug
This will run the script with the debug log level.
Output:
The script will generate two files: output.log that contains log messages based on the chosen
log level and output.html which is a HTML file presents the logged information in a user-friendly
format for viewing in a web browser.
b) Design consideration - what commands you used, how you constructed your script(s)
Shebang and Script Execution: The script begins with a shebang line #!/bin/bash,
indicating the interpreter required to execute the script (Bash shell).
Variable Declarations: The script utilizes variables to store configuration details like the log file
path (LOG_FILE) and default log level (LOG_LEVEL). This improves readability and
maintainability.
Modular Functions for Specific Tasks: The script employs well-defined functions for various
monitoring activities:
Command-Line Argument Parsing for Flexibility: The script leverages getopts to parse
command-line arguments, allowing users to specify the log level (-l). This empowers them to
control the detail level of logged information (verbose, debug, standard, or key-details).
The script generates two types of output: a log file (output.log) and an HTML file (output.html).
The log file contains the monitoring information logged by the script, while the HTML file
presents the log output in a web browser-friendly format.
The log level specified when running the script will determine the verbosity of the log output.
Advantages:
Modular Design: The script's modular structure promotes maintainability, reusability, and
efficient troubleshooting.
Configurable Logging: Users can tailor the logging verbosity to their needs, enabling focused
analysis.
HTML Output: The script generates HTML reports, facilitating data visualization in web
browsers and fostering collaboration.
Scheduling Automation: Integration with cron allows for automated, periodic monitoring,
eliminating manual intervention.
Disadvantages:
Functionality: While comprehensive, the script might require additional tools or features for in-
depth monitoring of specific system aspects.
Error Handling: The script's error handling capabilities could be enhanced to ensure more
robust operation in diverse scenarios.
Platform Nuances: While leveraging standard commands, minor variations across Unix-like
systems might necessitate script adjustments.
Scalability: Designed for single-system monitoring, it may not be optimal for large-scale
deployments. Additional solutions might be needed.
Data Analysis/Visualization: The script primarily focuses on log and HTML output. Advanced
data analysis or visualizations might require further processing or external tools.
e) Bibliography
For Bash Scripting:
Bash Guide for Beginners. Available at https://www.freecodecamp.org/news/bash-scripting-
tutorial-linux-shell-script-and-command-line-for-beginners/
Advanced Bash Scripting Guide. Available at https://tldp.org/LDP/abs/html/