Advertisement
sinisterstuf

Get PC Specs in Bash

Oct 29th, 2011
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #This script reports the following specs about your PC:
  4. # -How much space is available on each hard disk drive
  5. # -How much space is used/available on each mounted partition
  6. # -How much memory is available on each RAM device
  7. # -How fast is each CPU core (single core machines only have 1 entry)
  8. # -The name, driver used and memory available from your graphics accelerator
  9.  
  10. #Some of the commands in this script require root privelages, so
  11. #it will display an error if you try to run it as a normal user.
  12.  
  13. #Written by Siôn le Roux (sion@sionleroux.com)
  14. #This script is in the public domain, but it would be nice if you let
  15. #me know if you like it, or have any suggestions for improvements! :-)
  16.  
  17. #this is a function that outputs all the specs
  18. function check_my_specs() {
  19.     echo
  20.     echo " = PC Specs = "
  21.     echo #check the disk space with fdisk
  22.     echo "== Disk Space =="
  23.     fdisk -l | grep 'Disk .* bytes' | sed 's/, [0-9].*$//'
  24.     echo #check disk usage with df
  25.     echo "== Current Disk Usage =="
  26.     df -h | grep -e "^Filesystem" -e "^\/dev"
  27.     echo #I'm not very familiar with dmidecode but it can get RAM info
  28.     echo "== RAM =="
  29.     counter=0
  30.     dmidecode --type 17 | grep 'Size' | sed 's/^.//' | sed 's/S/s/' | while read -r ram
  31.     do #this for loop is used to display the number before the ram
  32.     counter=`expr $counter + 1`
  33.     echo "Slot "$counter" "$ram
  34.     done
  35.     echo #cpu info is read from /proc/cpu
  36.     echo "== CPU =="
  37.     counter=0
  38.     cat /proc/cpuinfo | grep 'name' | sed 's/.*\: //' | while read -r cpu
  39.     do #this for loop is used to display the number before the cpu core
  40.     counter=`expr $counter + 1`
  41.     echo "Core "$counter": "$cpu
  42.     done
  43.     echo #after the 'subdomain' is found, it is used to get the card info
  44.     echo "== Graphics =="
  45.     lspci -vs `lspci | grep VGA | sed 's/ .*//'` | grep -e "Memory" -e "VGA" -e "Kernel" | sed 's/^.//' | sed 's/^[0-9].*\: //' | sed 's/(.*)//'
  46. }
  47.  
  48. #call the function above if root, otherwise display an error
  49. if [[ $UID -ne 0 ]]
  50. then
  51.     echo "This script needs to be run as root!"
  52. else
  53.     check_my_specs
  54. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement