
Kod: Tümünü seç
#!/usr/bin/env bash
# LC_ALL is intentionally NOT set here.
# LC_ALL overrides ALL other LC_* variables including LC_NUMERIC,
# which causes printf %.2f/%.3f to fail under tr_TR.UTF-8 locale.
# LANG provides Turkish character support; LC_NUMERIC=C ensures
# printf uses dot as decimal separator (bc always outputs dot).
export LANG=tr_TR.UTF-8
export LC_NUMERIC=C
# ==============================================================
# hardware_report.sh
# Hardware information reporter for GNU/Linux
# Uses: lm-sensors, nvidia-smi, smartctl, nvme-cli, hardinfo
# Author : commandwarrior
# System : Lenovo IdeaPad Gaming 3 15IHU6 / Linux Mint 22.2
# Version : 1.3
# Changes : - LC_ALL removed; LANG + LC_NUMERIC=C used instead.
# LC_ALL overrides LC_NUMERIC so v1.2 fix had no effect.
# - Physical Cores: unique core id count (fix from v1.2)
# - All other v1.1 fixes retained
# ==============================================================
# --- ANSI color codes ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
RESET='\033[0m'
# --- Report output directory ---
REPORT_DIR="$HOME/hardware_reports"
# ==============================================================
# HELPER FUNCTIONS
# ==============================================================
print_header() {
clear
echo -e "${CYAN}${BOLD}"
echo " ╔══════════════════════════════════════════════════════╗"
printf " ║ %-50s ║\n" "$1"
echo " ╚══════════════════════════════════════════════════════╝"
echo -e "${RESET}"
}
print_section() {
echo -e "\n${YELLOW}${BOLD} >>> $1${RESET}"
echo -e "${DIM} $(printf '%.0s-' {1..54})${RESET}"
}
print_ok() { echo -e " ${GREEN}[OK]${RESET} $1"; }
print_warn() { echo -e " ${YELLOW}[WARN]${RESET} $1"; }
print_err() { echo -e " ${RED}[ERR]${RESET} $1"; }
print_info() { echo -e " ${CYAN}[INFO]${RESET} $1"; }
check_cmd() { command -v "$1" &>/dev/null; }
# ==============================================================
# SECTIONS
# ==============================================================
section_system() {
print_section "System Overview"
local os kernel host uptime_str user
os=$(lsb_release -d 2>/dev/null | cut -d: -f2 | xargs)
kernel=$(uname -r)
host=$(hostname)
uptime_str=$(uptime -p 2>/dev/null || uptime)
user=$(whoami)
printf " %-16s: %s\n" "Hostname" "$host"
printf " %-16s: %s\n" "OS" "$os"
printf " %-16s: %s\n" "Kernel" "$kernel"
printf " %-16s: %s\n" "Uptime" "$uptime_str"
printf " %-16s: %s\n" "User" "$user"
printf " %-16s: %s\n" "Date/Time" "$(date '+%Y-%m-%d %H:%M:%S')"
printf " %-16s: %s\n" "Architecture" "$(uname -m)"
}
section_cpu() {
print_section "CPU Information"
local model cores threads freq_min freq_max
model=$(grep 'model name' /proc/cpuinfo | head -1 | cut -d: -f2 | xargs)
cores=$(grep '^core id' /proc/cpuinfo | sort -u | wc -l)
threads=$(grep -c '^processor' /proc/cpuinfo)
freq_min=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq 2>/dev/null)
freq_max=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq 2>/dev/null)
printf " %-16s: %s\n" "Model" "$model"
printf " %-16s: %s\n" "Physical Cores" "$cores"
printf " %-16s: %s\n" "Threads" "$threads"
if [ -n "$freq_min" ] && [ -n "$freq_max" ]; then
printf " %-16s: %.2f GHz\n" "Min Freq" "$(echo "scale=2; $freq_min/1000000" | bc)"
printf " %-16s: %.2f GHz\n" "Max Freq" "$(echo "scale=2; $freq_max/1000000" | bc)"
fi
echo ""
print_info "Current per-core frequency:"
grep 'cpu MHz' /proc/cpuinfo | awk -v i=0 '{printf " Core %-2d : %s MHz\n", i++, $4}'
}
section_memory() {
print_section "Memory (RAM)"
free -h | awk '
NR==1 { printf " %-12s %-8s %-8s %-8s\n", "", $1, $2, $3 }
NR==2 { printf " %-12s %-8s %-8s %-8s\n", "RAM", $2, $3, $4 }
NR==3 { printf " %-12s %-8s %-8s %-8s\n", "Swap", $2, $3, $4 }
'
echo ""
if check_cmd dmidecode; then
print_info "Physical RAM slot details (requires sudo):"
sudo dmidecode --type 17 2>/dev/null | \
grep -E '^\s+(Size|Type:|Speed|Configured Memory Speed|Manufacturer|Part Number|Locator):' | \
grep -v 'No Module Installed' | \
sed 's/^[[:space:]]*/ /'
else
print_warn "dmidecode not found. Install: sudo apt install dmidecode"
fi
}
section_sensors() {
print_section "Thermal Sensors (lm-sensors)"
if check_cmd sensors; then
sensors 2>/dev/null | sed 's/^/ /'
else
print_warn "lm-sensors not found. Install: sudo apt install lm-sensors"
fi
}
section_gpu() {
print_section "GPU Information"
if check_cmd nvidia-smi; then
local raw
raw=$(nvidia-smi \
--query-gpu=name,temperature.gpu,power.draw,power.limit,fan.speed,\
utilization.gpu,utilization.memory,memory.used,memory.total,driver_version,pstate \
--format=csv,noheader,nounits 2>/dev/null)
if [ -n "$raw" ]; then
IFS=',' read -r gpu_name gpu_temp gpu_pow gpu_powlim gpu_fan \
gpu_util gpu_mem_util gpu_mem_used gpu_mem_total gpu_drv gpu_pstate <<< "$raw"
printf " %-20s: %s\n" "Name" "$(echo "$gpu_name" | xargs)"
printf " %-20s: %s C\n" "Temperature" "$(echo "$gpu_temp" | xargs)"
printf " %-20s: %s W / %s W\n" "Power Draw/Limit" "$(echo "$gpu_pow" | xargs)" \
"$(echo "$gpu_powlim" | xargs)"
printf " %-20s: %s RPM\n" "Fan Speed" "$(echo "$gpu_fan" | xargs)"
printf " %-20s: %s%%\n" "GPU Utilization" "$(echo "$gpu_util" | xargs)"
printf " %-20s: %s%%\n" "MEM Utilization" "$(echo "$gpu_mem_util" | xargs)"
printf " %-20s: %s / %s MiB\n" "VRAM Used/Total" "$(echo "$gpu_mem_used" | xargs)" \
"$(echo "$gpu_mem_total" | xargs)"
printf " %-20s: %s\n" "Driver Version" "$(echo "$gpu_drv" | xargs)"
printf " %-20s: %s\n" "Performance State" "$(echo "$gpu_pstate" | xargs)"
fi
else
print_warn "nvidia-smi not found."
print_info "Detected GPUs (lspci):"
lspci 2>/dev/null | grep -iE 'vga|3d|display' | sed 's/^/ /'
fi
echo ""
print_info "Intel Iris Xe (integrated) driver:"
lspci 2>/dev/null | grep -i 'Intel.*Iris' | sed 's/^/ /' || echo " N/A"
}
section_storage() {
print_section "Storage Devices"
echo ""
print_info "Block device layout:"
lsblk -o NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINT,MODEL 2>/dev/null | sed 's/^/ /'
echo ""
print_info "Filesystem usage:"
df -hT 2>/dev/null | grep -vE 'tmpfs|udev|loop' | sed 's/^/ /'
}
section_nvme() {
print_section "NVMe SSD Health (nvme-cli)"
if check_cmd nvme; then
local dev
dev=$(lsblk -d -o NAME,TYPE 2>/dev/null | awk '/nvme/{print "/dev/"$1}' | head -1)
if [ -n "$dev" ]; then
printf " %-24s: %s\n" "Device" "$dev"
echo ""
sudo nvme smart-log "$dev" 2>/dev/null | \
grep -E 'temperature|data_units_read|data_units_written|power_on_hours|unsafe_shutdowns|critical_warning|media_errors|percentage_used' | \
sed 's/^/ /'
else
print_warn "No NVMe device found."
fi
else
print_warn "nvme-cli not installed. Install: sudo apt install nvme-cli"
fi
}
section_hdd_smart() {
print_section "HDD SMART Data (smartmontools)"
if check_cmd smartctl; then
local dev
dev=$(lsblk -d -o NAME,TYPE,ROTA 2>/dev/null | awk '$2=="disk" && $3=="1"{print "/dev/"$1}' | head -1)
if [ -n "$dev" ]; then
printf " %-24s: %s\n" "Device" "$dev"
local model serial
model=$(sudo smartctl -i "$dev" 2>/dev/null | grep 'Device Model' | cut -d: -f2 | xargs)
serial=$(sudo smartctl -i "$dev" 2>/dev/null | grep 'Serial Number' | cut -d: -f2 | xargs)
printf " %-24s: %s\n" "Model" "$model"
printf " %-24s: %s\n" "Serial" "$serial"
echo ""
print_info "Key SMART attributes:"
sudo smartctl -A "$dev" 2>/dev/null | \
awk 'NR>6 && NF>=10' | \
grep -E 'Temperature|Reallocated|Pending|Uncorrectable|Power_On|Start_Stop|Load_Cycle|Seek_Error|Spin_Retry' | \
awk '{printf " %-36s RAW=%s\n", $2, $10}'
else
print_warn "No rotational HDD found."
fi
else
print_warn "smartmontools not installed. Install: sudo apt install smartmontools"
fi
}
section_battery() {
print_section "Battery Status"
local bat_path="/sys/class/power_supply/BAT1"
if [ -d "$bat_path" ]; then
local status capacity energy_now energy_full energy_full_design voltage
status=$(cat "$bat_path/status" 2>/dev/null || echo "N/A")
capacity=$(cat "$bat_path/capacity" 2>/dev/null || echo "N/A")
energy_now=$(cat "$bat_path/energy_now" 2>/dev/null)
energy_full=$(cat "$bat_path/energy_full" 2>/dev/null)
energy_full_design=$(cat "$bat_path/energy_full_design" 2>/dev/null)
voltage=$(cat "$bat_path/voltage_now" 2>/dev/null)
printf " %-24s: %s\n" "Status" "$status"
printf " %-24s: %s%%\n" "Charge Level" "$capacity"
if [ -n "$voltage" ]; then
printf " %-24s: %.3f V\n" "Voltage" "$(echo "scale=3; $voltage/1000000" | bc)"
fi
if [ -n "$energy_now" ] && [ -n "$energy_full" ]; then
printf " %-24s: %.2f Wh\n" "Energy Now" "$(echo "scale=2; $energy_now/1000000" | bc)"
printf " %-24s: %.2f Wh\n" "Energy Full" "$(echo "scale=2; $energy_full/1000000" | bc)"
fi
if [ -n "$energy_full" ] && [ -n "$energy_full_design" ]; then
local health
health=$(echo "scale=1; $energy_full * 100 / $energy_full_design" | bc 2>/dev/null)
printf " %-24s: %s%%\n" "Battery Health" "$health"
fi
elif check_cmd acpi; then
acpi -b 2>/dev/null | sed 's/^/ /'
acpi -t 2>/dev/null | sed 's/^/ /'
else
print_warn "Battery info not available."
fi
}
section_network() {
print_section "Network Interfaces"
ip -brief addr show 2>/dev/null | sed 's/^/ /' || \
ifconfig 2>/dev/null | grep -E 'inet|^[a-z]' | sed 's/^/ /'
echo ""
print_info "Wireless adapter:"
iwconfig 2>/dev/null | grep -v 'no wireless' | grep -A4 'wlan\|wlp' | \
grep -E 'ESSID|Freq|Bit Rate|Link Quality|Signal' | sed 's/^/ /' || \
echo " (no active Wi-Fi data)"
}
section_hardinfo() {
print_section "Hardinfo CLI Report"
if check_cmd hardinfo; then
print_info "Generating hardinfo summary report (please wait)..."
echo ""
timeout 30 hardinfo -r 2>/dev/null | \
grep -vE '^\s*$|^#|generating' | \
head -120 | sed 's/^/ /'
echo ""
print_ok "Hardinfo scan complete."
else
print_warn "hardinfo not found. Install: sudo apt install hardinfo"
fi
}
# ==============================================================
# FULL REPORT RUNNER
# ==============================================================
run_full_report() {
section_system
section_cpu
section_memory
section_sensors
section_gpu
section_storage
section_nvme
section_hdd_smart
section_battery
section_network
section_hardinfo
}
# ==============================================================
# SAVE REPORT TO FILE (plain text, no ANSI codes)
# ==============================================================
save_report() {
local TIMESTAMP
TIMESTAMP=$(date '+%Y-%m-%d_%H-%M-%S')
local REPORT_FILE="$REPORT_DIR/hw_report_${TIMESTAMP}.txt"
mkdir -p "$REPORT_DIR"
print_info "Saving full hardware report to file..."
echo ""
{
echo "======================================================"
echo " HARDWARE REPORT"
echo " Generated : $(date '+%Y-%m-%d %H:%M:%S')"
echo " Hostname : $(hostname)"
echo " System : $(lsb_release -d 2>/dev/null | cut -d: -f2 | xargs)"
echo " Kernel : $(uname -r)"
echo "======================================================"
echo ""
echo "=== SYSTEM OVERVIEW ==="
echo " Uptime : $(uptime -p)"
echo " User : $(whoami)"
echo " Arch : $(uname -m)"
echo ""
echo "=== CPU ==="
grep 'model name' /proc/cpuinfo | head -1 | cut -d: -f2 | xargs | sed 's/^/ /'
echo " Physical Cores : $(grep '^core id' /proc/cpuinfo | sort -u | wc -l)"
echo " Threads : $(grep -c '^processor' /proc/cpuinfo)"
echo ""
echo "=== MEMORY ==="
free -h | sed 's/^/ /'
echo ""
echo "=== THERMAL SENSORS ==="
if check_cmd sensors; then
sensors 2>/dev/null | sed 's/^/ /'
else
echo " [N/A] lm-sensors not installed"
fi
echo ""
echo "=== GPU ==="
if check_cmd nvidia-smi; then
nvidia-smi \
--query-gpu=name,temperature.gpu,power.draw,fan.speed,utilization.gpu,memory.used,memory.total,driver_version \
--format=csv,noheader,nounits 2>/dev/null | \
awk -F',' '{
printf " Name : %s\n", $1
printf " Temperature : %s C\n", $2
printf " Power Draw : %s W\n", $3
printf " Fan Speed : %s RPM\n", $4
printf " GPU Util : %s%%\n", $5
printf " VRAM Used : %s / %s MiB\n", $6, $7
printf " Driver : %s\n", $8
}'
else
echo " [N/A] nvidia-smi not found"
fi
echo ""
echo "=== STORAGE ==="
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT,MODEL 2>/dev/null | sed 's/^/ /'
echo ""
df -hT 2>/dev/null | grep -vE 'tmpfs|udev|loop' | sed 's/^/ /'
echo ""
echo "=== NVME SMART ==="
if check_cmd nvme; then
local ndev
ndev=$(lsblk -d -o NAME,TYPE 2>/dev/null | awk '/nvme/{print "/dev/"$1}' | head -1)
[ -n "$ndev" ] && sudo nvme smart-log "$ndev" 2>/dev/null | sed 's/^/ /'
else
echo " [N/A] nvme-cli not installed"
fi
echo ""
echo "=== HDD SMART ==="
if check_cmd smartctl; then
local hdev
hdev=$(lsblk -d -o NAME,TYPE,ROTA 2>/dev/null | awk '$2=="disk" && $3=="1"{print "/dev/"$1}' | head -1)
[ -n "$hdev" ] && sudo smartctl -A "$hdev" 2>/dev/null | sed 's/^/ /'
else
echo " [N/A] smartmontools not installed"
fi
echo ""
echo "=== BATTERY ==="
local bp="/sys/class/power_supply/BAT1"
if [ -d "$bp" ]; then
echo " Status : $(cat "$bp/status" 2>/dev/null)"
echo " Capacity : $(cat "$bp/capacity" 2>/dev/null)%"
local ef efd
ef=$(cat "$bp/energy_full" 2>/dev/null)
efd=$(cat "$bp/energy_full_design" 2>/dev/null)
[ -n "$ef" ] && [ -n "$efd" ] && \
echo " Health : $(echo "scale=1; $ef*100/$efd" | bc)%"
fi
echo ""
echo "=== NETWORK ==="
ip -brief addr show 2>/dev/null | sed 's/^/ /'
} 2>&1 | sed 's/\x1b\[[0-9;]*m//g' > "$REPORT_FILE"
print_ok "Report saved: $REPORT_FILE"
}
# ==============================================================
# MAIN MENU
# ==============================================================
main_menu() {
while true; do
print_header "HARDWARE INFORMATION REPORTER v1.3"
echo -e " ${DIM}System: $(hostname) | $(lsb_release -s -d 2>/dev/null) | $(uname -r)${RESET}"
echo ""
echo -e " ${BOLD}${CYAN}--- Display Sections ---${RESET}"
echo -e " ${BOLD}[1]${RESET} System Overview"
echo -e " ${BOLD}[2]${RESET} CPU Information"
echo -e " ${BOLD}[3]${RESET} Memory (RAM)"
echo -e " ${BOLD}[4]${RESET} Thermal Sensors (lm-sensors)"
echo -e " ${BOLD}[5]${RESET} GPU Information (nvidia-smi)"
echo -e " ${BOLD}[6]${RESET} Storage Devices (lsblk + df)"
echo -e " ${BOLD}[7]${RESET} NVMe SSD Health (nvme-cli)"
echo -e " ${BOLD}[8]${RESET} HDD SMART Data (smartctl)"
echo -e " ${BOLD}[9]${RESET} Battery Status"
echo -e " ${BOLD}[N]${RESET} Network Interfaces"
echo -e " ${BOLD}[H]${RESET} Hardinfo CLI Report"
echo ""
echo -e " ${BOLD}${CYAN}--- Actions ---${RESET}"
echo -e " ${BOLD}[A]${RESET} Show All Sections"
echo -e " ${BOLD}[S]${RESET} Save Full Report to File"
echo -e " ${BOLD}[Q]${RESET} Quit"
echo ""
read -rp " Select option [1-9 / N / H / A / S / Q]: " choice
case "${choice^^}" in
1) clear; section_system ;;
2) clear; section_cpu ;;
3) clear; section_memory ;;
4) clear; section_sensors ;;
5) clear; section_gpu ;;
6) clear; section_storage ;;
7) clear; section_nvme ;;
8) clear; section_hdd_smart ;;
9) clear; section_battery ;;
N) clear; section_network ;;
H) clear; section_hardinfo ;;
A) clear; run_full_report ;;
S) echo ""; save_report ;;
Q) echo -e "\n ${GREEN}Goodbye.${RESET}\n"; break ;;
*) print_err "Invalid option: '$choice'" ;;
esac
echo ""
read -rp " Press ENTER to return to menu..." _
done
}
# ==============================================================
# ENTRY POINT
# ==============================================================
if [ "$EUID" -eq 0 ]; then
echo -e "${YELLOW}[WARN] Running as root. Some sections use 'sudo' internally -- this is fine.${RESET}"
sleep 1
fi
main_menu
read -rp $'\nPress ENTER to exit.' _

