System Information Checker

Comprehensive script that displays detailed hardware and software information on your Linux system. Shows CPU, RAM, disk usage, OS version and more.

Published: January 15, 2024 Updated: December 01, 2024

Detailed Information

This script collects all critical system information on your Linux system and presents it in an organized and readable format. It is an essential tool for system administrators, DevOps engineers, and IT professionals.

What Does This Script Do?

This script quickly analyzes your system's hardware and software status. It displays critical metrics such as CPU, RAM, disk usage, network information, and system uptime with a single command. It is particularly useful for server management, performance analysis, and troubleshooting.

What Information Does It Show?

  • Hostname: System name on the network
  • Operating System: OS name, version, kernel version, and architecture
  • CPU Information: Processor model, core count, and current usage percentage
  • Memory (RAM): Total, used, free memory, and usage percentage
  • Disk Usage: Usage status of all mounted disks
  • Network Information: System IP address
  • Uptime: How long the system has been running
  • Load Average: System load averages (1, 5, 15 minutes)
  • Last Logins: Last 5 user login records

Why Should You Use It?

With this script, you can quickly check your system status, detect performance issues, and create system documentation. Especially if you manage multiple servers, you can use this script to quickly see the status of each server.

How to Use

Step-by-Step Usage Guide

1. Create the Script File

First, save the script to a file. For example, create a file named system_info.sh:

nano system_info.sh

Paste the script code into this file and save it (Ctrl+X, then Y, then Enter).

2. Make the Script Executable

To run the script, you need to give it execute permission:

chmod +x system_info.sh

3. Run the Script

Now you can run the script:

./system_info.sh

4. Review the Output

After the script runs, your system information will be displayed on the screen. If you want to save this information to a file:

./system_info.sh > system_report.txt

Daily Usage

You can track your system status by running this script regularly. For example, you can create a cron job to check system status every morning:

# Edit crontab
crontab -e

# Run every morning at 08:00 and save report
0 8 * * * /path/to/system_info.sh >> /var/log/system_reports.log

Advanced Usage

You can customize the script to show only specific information or save the output in a different format. For example, you can edit the script to see only disk usage.

Requirements

Requirements

  • Bash 4.0+: Script runs in bash shell
  • Linux/Unix System: Script works on Linux and Unix-based systems
  • System Tools: The following commands must be installed on your system:
    • lscpu - For CPU information
    • free - For memory information
    • df - For disk usage
    • uptime - For system uptime
    • last - For last logins
    • ip or ifconfig - For network information
    • top - For CPU usage
  • Permissions: Most commands work with normal user permissions, but root privileges may be required for some information

Installation Check

To check if required tools are installed:

which lscpu free df uptime last ip top

If any tools are missing, install them according to your system:

# Ubuntu/Debian
sudo apt-get install procps net-tools

# CentOS/RHEL
sudo yum install procps-ng net-tools

# Arch Linux
sudo pacman -S procps-ng net-tools

Use Cases

Use Cases

1. System Health Check

You can use this script to regularly check your system status. Especially in server management, it is very important to quickly see the status of system resources.

2. Performance Analysis

By monitoring CPU, RAM, and disk usage, you can detect performance issues. High usage rates may indicate that your system is overloaded.

3. Troubleshooting

When experiencing system problems, you can quickly check system status with this script. For example, you can detect disk fullness, high CPU usage, or memory issues.

4. System Documentation

When you get a new server or want to save system configuration, you can save the output of this script as documentation.

5. Server Comparison

If you have multiple servers, you can check and compare the status of each using this script.

6. Automated Reporting

You can create automated system reports by running this script regularly with a cron job.

Examples

Usage Examples

Example 1: Simple Usage

Run the script and display output on screen:

./system_info.sh

Example 2: Save Output to File

Save the report to a file:

./system_info.sh > system_report_$(date +%Y%m%d).txt

Example 3: Send via Email

Send the report via email:

./system_info.sh | mail -s "System Report" [email protected]

Example 4: Automatic Execution with Cron Job

Run every day at 08:00:

# Edit crontab
crontab -e

# Add:
0 8 * * * /path/to/system_info.sh >> /var/log/system_reports.log 2>&1

Example 5: Show Only Disk Usage

You can edit the script to show only disk usage:

#!/bin/bash
echo "--- Disk Usage ---"
df -h | grep -E "^/dev/" | awk "{print \$1\": \"\$3\"/\"\$2\" (\"\$5\" used)\"}"

Code

#!/bin/bash

# System Information Checker Script

echo "======================================"
echo "   SYSTEM INFORMATION REPORT"
echo "======================================"
echo ""

echo "Hostname: $(hostname)"
echo ""

echo "--- Operating System ---"
if [ -f /etc/os-release ]; then
    . /etc/os-release
    echo "OS: $NAME"
    echo "Version: $VERSION"
fi
echo "Kernel: $(uname -r)"
echo "Architecture: $(uname -m)"
echo ""

echo "--- CPU Information ---"
echo "Model: $(lscpu | grep "Model name" | cut -d: -f2 | xargs)"
echo "Cores: $(nproc)"
echo "CPU Usage: $(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk "{print 100 - \$1\"%\"}")"
echo ""

echo "--- Memory Information ---"
free -h | awk "NR==2{printf \"Total: %s\nUsed: %s\nFree: %s\nUsage: %.2f%%\n\", \$2,\$3,\$4,\$3*100/\$2 }"
echo ""

echo "--- Disk Usage ---"
df -h | grep -E "^/dev/" | awk "{print \$1\": \"\$3\"/\"\$2\" (\"\$5\" used)\"}"
echo ""

echo "--- Network Information ---"
ip -4 addr show | grep -oP "(?<=inet\s)\d+(\.\d+){3}" | head -n 1 | xargs echo "IP Address:"
echo ""

echo "--- System Uptime ---"
uptime -p
echo ""

echo "--- Load Average ---"
uptime | awk -F"load average:" "{print \$2}"
echo ""

echo "--- Last Login ---"
last -n 5 | head -n 5
echo ""

echo "======================================"
echo "Report generated: $(date)"
echo "======================================"

Usage

chmod +x system_info.sh
./system_info.sh

Troubleshooting

Troubleshooting

Problem: "command not found" Error

Solution: Make sure required system tools are installed. See the "Requirements" section above.

Problem: CPU Usage Not Displayed

Solution: Make sure top command is installed. Alternatively, you can use htop or vmstat.

Problem: IP Address Not Displayed

Solution: If ip command is not available, use ifconfig. Edit the script as follows:

if command -v ip &> /dev/null; then
    ip -4 addr show | grep -oP "(?<=inet\s)\d+(\.\d+){3}" | head -n 1
else
    ifconfig | grep -oP "inet \K[\d.]+" | head -n 1
fi

Problem: Disk Information Missing

Solution: Make sure df command works. On some systems, check the /proc/mounts file.

Problem: Script Not Running

Solution:

  • Make sure the script has execute permission: chmod +x system_info.sh
  • Run with bash: bash system_info.sh
  • Check the shebang line at the beginning of the script: #!/bin/bash

Tags

system info cpu ram disk usage monitoring