• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Disk info utility in Linux

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Dreamstalker

Member
Joined
Nov 13, 2004
Location
Brookline, MA
I've run into a bit of a snag with one assignment for my Linux class; writing a util (shell script) that will gather data on user machines (kernel version, CPU info, hardware, memory, who's logged in, etc). I know how to extract what I need (sort of; using dmesg, pstree and lsmod), but I'm not completely sure how to extract a single line from dmesg/lsmod to output (CPU info on one line, memory capacity output on another line, etc). Is that possible?

What I'm looking for is a similar script so I know what the final outcome should be (to work backwards for the bits I don't have). This class is using Knoppix 4.0
 
A couple things you should take a look at:

grep: This allows you to search a file for lines containing a certain text string. (It does a lot more, but this is the basic idea.) For example, you can do dmesg | grep pci to get it to return every line that has the string "pci".

Also, take a look at /proc. It is a bunch of dynamically created files that have system info in them. cpu info is stored, for example, in /proc/cpuinfo. Try "cat /proc/cpuinfo" and it will give you lots of cpu info.
 
kernel version: uname -r or uname -v
cpuinfo: cat /proc/cpuinfo | grep "model name"
hardware: need more specifics, what kind of hardware
meminfo: cat /proc/meminfo
logged in users: who

As for getting only certain lines from multiline output in shell scripting: man sed, man awk.
 
Back