Explanation:
Shebang:
#!/bin/bashspecifies that this script should be interpreted using the Bash shell.get_system_info Function: Gathers various system information using built-in Linux commands:
hostname: Prints the system hostname.sudo dmidecode -s ...: Retrieves system manufacturer, product name, version, and serial number usingdmidecode(requires sudo for some systems).grep -m 1 "model name" /proc/cpuinfo | cut -d ':' -f 2 | sed 's/^[ \t]*//': Gets processor model from/proc/cpuinfo.uname -m: Prints the system architecture.uname -r: Displays the kernel version.uptime -p: Shows system uptime.who: Lists currently logged in users.free -h: Displays memory usage in a human-readable format.df -h: Shows disk usage in a human-readable format.ip a: Lists network interfaces and their configurations.ps aux --sort -%cpu,%mem: Provides a list of running processes sorted by CPU and memory usage.
Execution: Calls the
get_system_infofunction to gather and display all system information.
Usage:
- Save this script to a file, e.g.,
system_info.sh. - Make it executable with
chmod +x system_info.sh. - Run the script with
./system_info.sh.
Notes:
Customization: Modify the script to include additional information or customize the output format according to your specific needs.
Security: Some commands (
dmidecode,sudo) may require appropriate permissions or adjustments depending on your system configuration. Ensure you have necessary privileges to execute them.Error Handling: This script assumes basic error handling. You may want to add more robust error checking and reporting based on your specific requirements.
This script provides a basic framework for gathering and displaying essential system information in a Unix-like environment using standard Linux commands. Depending on your needs, you can expand upon it to include more detailed monitoring, logging, or integration with other system management tools.
0 Comments