wget haganfox.net/qsi.txt
qsi.sh
(or just qsi
) is a shell script that reports important system information you can evaluate a glance.
The report shows an overview of the system's most significant properties. It answers some common questions you might have about the system's OS distribution, CPU, memory, kernel, filesystem, and network.
The original purpose of the script was to provide a block of text a system administrator would use to establish system changelog file (/etc/README.txt) on a freshly-installed Linux machine. It's useful any time you want to see important system information quickly.
The script works on a wide variety of systems and adapts to varying circumstances. It doesn't require Bash, and nothing the script does requires root privileges.
Example Output
=== 2016-10-28 14:41 EST System Information for LAPTOP-33 === Distribution: Ubuntu 14.04.5 LTS (2014-04) 1 CPU : Intel(R) Core(TM)2 Duo CPU T9600 @ 2.80GHz 2 cores, 2 logical cores, 6144K cache Memory: 3.8G RAM + 4.7G swap, with 942M + 4.7G free Kernel: Linux 3.13.0-100-lowlatency x86_64 #147-Ubuntu SMP PREEMPT Tue Oct 18 17:26:49 UTC 2016 Filesystems: /dev/sda2 is 268M ext3, with 131M available on /boot /dev/sda6 is 11G ext4, with 3.4G available on / /dev/sda7 is 37G ext4, with 21G available on /home 3 network interfaces: lo, eth0, wlan0 Gateway is 192.168.42.254/24 via wlan0 with IP 192.168.42.133
The Script
Text version: qsi.txt <---Right-click to download. Alternatively use wget
:
wget http://www.haganfox.net/site/uploads/Main.QuickSystemInfo/qsi.txt
MD5SUM: 2898ae6b7401a289d1f2197279987685
SHASUM: 7c529b0897ed2d1f029719e0b0b776aee91e31f3
SHA256SUM: 19ca9d2f98c38953c08c37252e5e9585ef6e1542c430a7a00298622666615464
#!/bin/sh # # qsi(.sh) -- Prints a Quick System Information summary about the system's # OS distribution, CPU, memory, kernel, filesystem(s), and network. # # http://www.haganfox.net/Main/QuickSystemInfo ## Settings # ## $SHOWFS determines if the Filesystem section will appear. ## 1 means show it, 0 means leave it out. SHOWFS=1 # ## $FSMOUNTS is a comma-separated whitelist of filesystems ## that may be mounted on devices in /dev/ . FSMOUNTS='/,/boot,/home,/opt,/root,/usr,/usr/local,/tmp,/var,/storage' # Title DATE=$(date "+%F %H:%M %Z") HOSTNAME=$(hostname) # Distribution if test -f /etc/lsb-release; then DIST=$(grep DESCRIPTION /etc/lsb-release | awk -F'=' '{print $NF}' | tr -d \") elif test -f /etc/os-release; then D1=$(grep ^NAME\= /etc/os-release | awk -F'=' '{print $NF}' | tr -d \") if grep ^VERSION\= /etc/os-release >/dev/null; then # version if available D2=" $(grep ^VERSION\= /etc/os-release | awk -F'=' '{print $NF}' | tr -d \")" fi DIST="$D1$D2" else DIST=$(cat /proc/version \ | awk -F')' '{print $(NF-2)}' \ | awk -F'(' '{print $NF}') fi if test -f /etc/os-release; then # sometimes ID shows "derived from" DISTID="$(grep ^ID\= /etc/os-release | awk -F'=' '{print $NF}') " fi DISTDATE=$(find /etc -type d 2>/dev/null \ | xargs ls -d --full-time 2>/dev/null \ | awk '{print $6}' \ | awk -F'-' '{print $1"-"$2}' \ | sort \ | uniq -c \ | sort -n \ | awk 'END{print $2}') # CPU CPUCOUNT=$(grep "^physical id" /proc/cpuinfo | sort -u | wc -l ) if test $CPUCOUNT -gt 1; then # multiple CPUs? CPUS="s"; else CPUS=" "; fi CPUMODEL=$(grep '^model name' /proc/cpuinfo \ | awk -F': ' 'NR==1{print $NF}' \ | tr -s " ") ACORECOUNT=$(grep "^core id" /proc/cpuinfo | sort -u | wc -l) LCORECOUNT=$(grep -c '^processor' /proc/cpuinfo) if $(which lscpu >/dev/null 2>&1); then # has lscpu? CPUL2=$(lscpu | grep "^L2 cache" | awk '{print $NF}') else CPUL2="unknown" fi # Memory if free -h >/dev/null 2>&1; then # support -h? dh=-h; fi RAM=$(free $dh | grep Mem | awk '{print $2}') RAMF=$(free $dh | grep Mem | awk '{print $4}') SWAP=$(free $dh | grep Swap | awk '{print $2}') SWAPF=$(free $dh | grep Swap | awk '{print $4}') # Kernel if test -x /bin/uname >/dev/null; then # can use uname? KERNEL=$(uname -srm) KVER=$(uname -v) elif $(which php >/dev/null); then # try PHP KNAME=$(php -r "echo php_uname('s');") KREV=$(php -r "echo php_uname('r');") KHW=$(php -r "echo php_uname('m');") KERNEL="$KNAME $KREV $KHW" KVER=$(php -r "echo php_uname('v');") else KERNEL="unknown kernel name" KVER="unknown kernel version" fi # Filesystem if test "$1" = "-f"; then SHOWFS=0; fi # -f parameter hides if test "$1" = "+f"; then SHOWFS=1; fi # +f parameter shows if test $SHOWFS = 1; then devmounts=$(df 2>/dev/null | grep '^/dev/'[A-Za-z] | sort | awk '{print $6}') n=1 for mount in $devmounts; do IFS="," # field separator for FSM in $FSMOUNTS; do if test x$mount = x$FSM; then # has a device FSN=$(df $FSM | awk 'NR==2{print $1}') # filesystem FSS=$(df -h $FSM | awk 'NR==2{print $2}') # size FST=$(df -T $FSM | awk 'NR==2{print $2}') # type FSA=$(df -h $FSM | awk 'NR==2{print $4}') # avail if test $n -gt 1; then FSL=" $sp" fi FS="$FS$(printf %b \ "$FSL $FSN is $FSS $FST, with $FSA available on $FSM") " sp=" " n=$(expr $n + 1) fi done done if test $n -eq 1; then # no mounts FSL="Filesystem: No mounts were found. (Live-boot?) " elif test $n -eq 2; then # one mount FSL="Filesystem:" else # multiple mounts FSL="Filesystems:" fi fi # Network if ! echo :$PATH: | grep -q ":/sbin:"; then # $PATH has /sbin? PATH=$PATH:/sbin; fi IFCOUNT=$(ip -o link show | wc -l) IFNAMES=$(ip -o link show | awk -F':' '{print $2}' | paste -s -d, -) GW=$(ip route get 8.8.8.8 | awk 'NR==1{print $3}') if ip addr | grep -q 'state UP'; then # is "state UP" shown? MASK="/$(ip addr \ | grep -A2 'state UP' \ | awk 'END{print $2}' \ | awk -F'/' '{print $2}')" fi GWNIC=$(ip route get 8.8.8.8 | awk 'NR==1{print $5}') IPADDR=$(ip route get 8.8.8.8 | awk 'NR==1{print $7}') # Output cat << EOT === $DATE System Information for $HOSTNAME === Distribution: $DIST ($DISTID$DISTDATE) $CPUCOUNT CPU$CPUS: $CPUMODEL $ACORECOUNT cores, $LCORECOUNT logical cores, $CPUL2 cache Memory: $RAM RAM + $SWAP swap, with $RAMF + $SWAPF free Kernel: $KERNEL $KVER $FSL$FS$IFCOUNT network interfaces:$IFNAMES EOT if test x = x$GW; then echo "There is no gateway address." else echo "Gateway is $GW$MASK via $GWNIC with IP $IPADDR" fi
Installation
You can run the script as a system-wide executable or your can run it locally.
System-wide Installation
Download the script, rename it to qsi.
mv qsi.txt qsi
Set the owner and permissions.
chmod 755 qsi
sudo chown root.root qsi
Put the file in /usr/local/bin/.
sudo mv qsi /user/local/bin/
Run the script system-wide with
qsi
Local Installation
Download the script, rename it to qsi.sh.
mv qsi.txt qsi.sh
Set permissions.
chmod 700 qsi.sh
Run the script locally with
./qsi.sh
Questions Answered
General
- When was the report created?
- What's the hostname?
- What distribution is installed?
- What's the distribution's date?
CPU
- How many CPUs are installed?
- What model CPU(s)?
- How many actual CPU cores?
- How many logical CPU cores?
- How much L2 Cache?
Memory
- How much RAM is installed?
- How much swap space is allocated?
- How much RAM is free?
- How much swap is free?
Kernel
- What kernel is running?
- What's the kernel version?
Filesystem
(for each mounted filesystem in the whitelist)
- Which directories are separate mounted filesystems?
- What is the/each filesystem type?
- How large is the/each filesystem?
- What partition is the/each filesystem mounted on?
- How much space is available?
Network
- How many network interfaces?
- What are the network interfaces' names?
- What's the default gateway?
- Which interface points to the default gateway?
- What's that interface's IP address?
- What's the netmask?
What it Does
- Get the date, time, and time zone.
- Get the hostname.
- Test to see if /etc/lsb-release exists.
- If so, get distribution information.
- If not, try the same with /etc/os-release .
- If not, refer to /proc/version.
- Get the number of physical CPUs.
- Get the CPU model.
- Count the number of actual cores.
- Count the number of logical cores.
- Determine if the lscpu command is available,
- if so, get the amount of L2 cache,
- if not use "unknown".
- Determine if the free command supports the -h (human readable) option.
- Get RAM and swap statistics (total and free, in human-readable format if available).
- Check whether the uname command is available.
- If so, use uname to get the kernel (name/release/machine) and kernel version information.
- If not, check if command-line PHP is available and use that instead to get the same information.
- Add ":/sbin" to the command path if it's not included.
- Get the number of network interfaces.
- Get the names of the network interfaces.
- Get the number of gateway address(es), if any.
- Count the number of dots in the gateway-address results.
- Determine the IP address of the interface that points to the gateway IP address(es).
- Print the report, except the last line (network information).
- Only print the network information if one gateway was reported.
- If there's no gateway, report that.
- If there are multiple gateways, report that.
Commands Used
- date
- print the system date
- hostname
- show the system's host name
- test
- compare values
- grep
- print lines matching a pattern
- awk
- pattern scanning and processing
- cat
- send text to standard output
- sort
- sort lines of text files
- wc
- print newline counts
- tr
- delete characters
- which
- shows the path of a command
- lscpu
- display CPU information
- free
- display the amount memory
- uname
- print system information
- php
- command line PHP command
- df
- report file system disk space usage
- echo
- display a line of text
- printf
- format and print data
- expr
- evaluate expressions
- ip
- display interface properties
- paste
- merge lines of files
- route
- show the IP routing table
Changelog
2016-10-24
- Added a line of information about the root filesystem.
2016-10-26
- Now getting OS version from /proc/version if /etc/lsb-release isn't present.
- Switched to a more reliable way of determining the gateway and network interface settings.
- On systems with multiple gateways, the one that reaches the Internet is shown now.
- The CIDR-notation netmask, if attainable, is shown after the gateway address.
- Improved the filesystem section so it dynamically includes filesystems than / (the root filesystem).
- Added a setting to either display the Filesystem section or leave it out of the report.
- New
-f
and+f
parameters will hide/show the Filesystem section regardless of how the default is set. - Added a setting that provides a configurable whitelist of directories that could possibly be mounted filesystems.
2016-10-28
- Improved the Filesystem section.
- For a single filesystem the label says "Filesystem:" and for two or more it says "Filesystems:".
- Rearranged the items so they're easier to scan visually.
- Add a reliable best-guess of the originally-installed distribution's date (month and year) to the Distribution line. On some upgraded systems it can report an older date than that of the current distro. In the example output above you can tell Ubuntu Studio 14.04.0 was originally installed and the system has been upgraded to 14.04.5, which is useful information.
2017-02-02
- Improved distribution-date detection. Now the year is always shown accurately.
2017-02-23
- Added sorting when there are multiple lines in the filesystems section.
2017-12-30
- Added the time and time zone to the date string.
2018-10-24
- Get IP slightly differently for compatibility with Manjaro/Arch.
2019-01-02
- Adapt to a system where no filesystems are found (for Live OS compatibility).
- Adapt to a system where no /etc/lsb-release is present (e.g. Debian stretch).
2019-01-07
- Add distribution ID, when available, to the Distribution line. This ID sometimes shows which distribution the installed OS is derived from.
2019-01-08
- Include the version only if a VERSION line is present.
ToDo
- Test the script in a multi-CPU system.
Other System Information Options
System Info Command (inxi)
Need more details? Try this:
inxi -Fxzc0
-F Full output -x add verbosity -z Hide MAC address -C0 Color Scheme 0 (monochrome)
It'll show you information with these headings: System, Machine, CPU, Graphics, Audio, Network, Drives, Partition, RAID, Sensors, Info. Learn more: https://github.com/smxi/inxi
List Hardware (lshw)
The lshw (list hardware) command provides some detailed information about hardware, including what memory is installed.
sudo lshw -short
-short means "output hardware paths"