The /proc virtual filesystem is one of the most interesting virtual filesystems available on Linux. Here you can see more information about your running system than you would know what to do with, including system information, memory information, CPU information, and much more.
Mining /proc for information can be invaluable if you need to find something out, such as what kind of processor the system is running or how much memory it has available.
Here is a script that illustrates some of the things you can do with /proc and how you can and format it for display. Whether this is just for curiosity or part of inventory or logging for a particular system, this script can be used and extended in a variety of ways. Its main purpose here is to show how much information can be gleaned from /proc.
#!/bin/sh
echo "System Information"
echo "------------------"
echo " hostname: `cat /proc/sys/kernel/hostname`"
echo " kernel: `cat /proc/sys/kernel/osrelease`"
echo ""
echo "Mounted Filesystems"
echo "-------------------"
cat /proc/mounts | sort
echo ""
echo "Available SWAP"
echo "--------------"
cat /proc/swaps
echo ""
echo "Disk Devices By Controller"
echo "--------------------------"
for dev in `ls /proc/ide | grep ide`; do
echo "${dev}:"
for disk in `ls /proc/ide/${dev}`; do
pdev="/proc/ide/${dev}/${disk}"
if [ -f ${pdev}/driver ]; then
echo " /dev/${disk}"
echo " --------"
[[ -f ${pdev}/model ]] && echo " model: `cat ${pdev}/model`"
[[ -f ${pdev}/cache ]] && echo " cache: `cat ${pdev}/cache`"
[[ -f ${pdev}/capacity ]] && echo " capacity: `cat ${pdev}/capacity`"
[[ -f ${pdev}/media ]] && echo " type: `cat ${pdev}/media`"
echo ""
fi
done
done
echo "CPU Information"
echo "---------------"
cat /proc/cpuinfo
Below is what the output of this script might look like.
~/ >% sh proc-mine
System Information
------------------
hostname: artemis.annvix.org
kernel: 2.6.16.29-6190avx
Mounted Filesystems
-------------------
/dev/hda1 /boot ext2 rw,noatime,nogrpid 0 0
/dev/hda5 /usr/local ext3 rw,nodev,noatime,data=ordered 0 0
/dev/hda6 /home xfs rw,nosuid,nodev 0 0
/dev/hdc1 /srv xfs rw,nosuid,nodev,noexec 0 0
/dev/root / ext3 rw,noatime,data=ordered 0 0
/dev/sda1 /backup/master xfs rw 0 0
/dev/sdb1 /backup/mirror xfs rw 0 0
artemis:(pid13162,port1022) /net nfs rw,sync,v2,rsize=1024,wsize=1024,acregmin=0,acregmax=0,acdirmin=0,acdirmax=0,
hard,intr,noac,lock,proto=udp,addr=pid13162@artemis:/net 0 0
none /dev/pts devpts rw 0 0
none /dev/shm tmpfs rw,nosuid,noexec 0 0
none /proc proc rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
none /sys sysfs rw,nosuid,nodev,noexec 0 0
rootfs / rootfs rw 0 0
Available SWAP
--------------
Filename Type Size Used Priority
/dev/hda2 partition 987988 360 -1
Disk Devices By Controller
--------------------------
ide0:
/dev/hda
--------
model: Maxtor 6Y200P0
cache: 7936
capacity: 398297088
type: disk
/dev/hdb
--------
model: LITE-ON DVDRW SOHW-1633S
capacity: 0
type: cdrom
ide1:
/dev/hdc
--------
model: Maxtor 6Y200P0
cache: 7936
capacity: 398297088
type: disk
CPU Information
---------------
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 47
model name : AMD Athlon(tm) 64 Processor 3500+
stepping : 2
cpu MHz : 2202.911
cache size : 512 KB
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm 3dnowext 3dnow pni lahf_lm
bogomips : 4416.00
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp tm stc



1
krisk - 31/01/08
Cool
» Report offensive content