Linux commands to get hardware specs?

TheHiveMind

Banned
Joined
Jul 25, 2008
Messages
5,073
Reaction score
4
Location
The Big Wide World
Im using SuSE Linux.

I need the collect the following info for a hardware profile on a few machines.

CPU (make and speed)
Ram
HD total/free space for all HD's

How would I collect that info by using linux commands?


Thanks
 
Code:
#!/bin/bash
#
# Simple shell script that calculates total hdd space and free space.

for prog in awk perl
do
    if [ -z `which $prog` ]; then
        echo "WTF you don't have ${prog} installed - bailing."
        exit 1
    fi
done
TOTAL_SPACE=`df | grep /dev | awk '{total+=$2}END{print total/1024/1024}'`
TOTAL_USED=`df | grep /dev | awk '{total+=$3}END{print total/1024/1024}'`
TOTAL_FREE=`df | grep /dev | awk '{total+=$4}END{print total/1024/1024}'`
PERC_USED=`perl -e 'printf("%.2f%\n", '$TOTAL_USED'/'$TOTAL_SPACE'*100);'`
echo "Current used space is ${TOTAL_USED}GB of ${TOTAL_SPACE}GB (${PERC_USED})."
echo "Current free space is ${TOTAL_FREE}GB."
 
Code:
#!/bin/bash
#
# Simple shell script that enumerates each CPU core and installed memory.

nCPU=`cat /proc/cpuinfo | grep -c 'processor'`
declare -a CPU[${nCPU}]
MEM=`free -t | grep -w 'Mem' | awk '{print $2}'`
SWAP=`free -t | grep -w 'Swap' | awk '{print $2}'`
let MEM="$MEM/1024"
let SWAP="$SWAP/1024"
echo
for i in `seq 1 ${nCPU}`
do
    CPUMOD=`cat /proc/cpuinfo | grep -m 1 -w 'model name' | awk -F: '{print $2}'`
    CPUSPEC=`cat /proc/cpuinfo | grep -m 1 -w 'cpu MHz' | awk -F: '{print $2}'`
    echo "CPU[${i}]:${CPUMOD} @${CPUSPEC} MHz"
done
echo "MEM   : ${MEM}MB"
echo "SWAP  : ${SWAP}MB"
echo
 
Personally I am a fan of `lshw`, unfortunately it doesn't come standard with linux (the distro's I've worked with).
 
hwinfo is not installed by default it has to be installed on suse
 
lshw is awesome. I don't vouch for this repo, but there are some rpms here but as far as I remember it compiles cleanly and quickly on SUSE provided your GCC installed.
 
Code:
#!/bin/bash
#
# Simple shell script that calculates total hdd space and free space.

for prog in awk perl
do
    if [ -z `which $prog` ]; then
        echo "WTF you don't have ${prog} installed - bailing."
        exit 1
    fi
done
TOTAL_SPACE=`df | grep /dev | awk '{total+=$2}END{print total/1024/1024}'`
TOTAL_USED=`df | grep /dev | awk '{total+=$3}END{print total/1024/1024}'`
TOTAL_FREE=`df | grep /dev | awk '{total+=$4}END{print total/1024/1024}'`
PERC_USED=`perl -e 'printf("%.2f%\n", '$TOTAL_USED'/'$TOTAL_SPACE'*100);'`
echo "Current used space is ${TOTAL_USED}GB of ${TOTAL_SPACE}GB (${PERC_USED})."
echo "Current free space is ${TOTAL_FREE}GB."


Wow.. an entire script to print out 'df -h' :-/


CPU :
# cat /proc/cpuinfo

Memory :
# free -m

Disk Space:
# df -h

Motherboard components:
# lspci
 
Wow.. an entire script to print out 'df -h' :-/

Actually, no, it prints out the *total* hard drive space, (this is what the OP asked for), and percentage used while ignoring any network mounts. Come back and anklebite me after you've actually run the script :rolleyes:.
 
Top
Sign up to the MyBroadband newsletter
X