27.08.2015 Views

Advanced Bash−Scripting Guide

Advanced Bash-Scripting Guide - Nicku.org

Advanced Bash-Scripting Guide - Nicku.org

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Advanced</strong> <strong>Bash−Scripting</strong> <strong>Guide</strong><br />

bash$ cat /proc/interrupts<br />

CPU0<br />

0: 84505 XT−PIC timer<br />

1: 3375 XT−PIC keyboard<br />

2: 0 XT−PIC cascade<br />

5: 1 XT−PIC soundblaster<br />

8: 1 XT−PIC rtc<br />

12: 4231 XT−PIC PS/2 Mouse<br />

14: 109373 XT−PIC ide0<br />

NMI: 0<br />

ERR: 0<br />

bash$ cat /proc/partitions<br />

major minor #blocks name<br />

rio rmerge rsect ruse wio wmerge wsect wuse running use aveq<br />

3 0 3007872 hda 4472 22260 114520 94240 3551 18703 50384 549710 0 111550 644030<br />

3 1 52416 hda1 27 395 844 960 4 2 14 180 0 800 1140<br />

3 2 1 hda2 0 0 0 0 0 0 0 0 0 0 0<br />

3 4 165280 hda4 10 0 20 210 0 0 0 0 0 210 210<br />

...<br />

bash$ cat /proc/loadavg<br />

0.13 0.42 0.27 2/44 1119<br />

Shell scripts may extract data from certain of the files in /proc. [59]<br />

bash$ cat /proc/filesystems | grep iso9660<br />

iso9660<br />

kernel_version=$( awk '{ print $3 }' /proc/version )<br />

CPU=$( awk '/model name/ {print $4}' < /proc/cpuinfo )<br />

if [ $CPU = Pentium ]<br />

then<br />

run_some_commands<br />

...<br />

else<br />

run_different_commands<br />

...<br />

fi<br />

The /proc directory contains subdirectories with unusual numerical names. Every one of these names maps<br />

to the process ID of a currently running process. Within each of these subdirectories, there are a number of<br />

files that hold useful information about the corresponding process. The stat and status files keep running<br />

statistics on the process, the cmdline file holds the command−line arguments the process was invoked with,<br />

and the exe file is a symbolic link to the complete path name of the invoking process. There are a few more<br />

such files, but these seem to be the most interesting from a scripting standpoint.<br />

Chapter 28. /dev and /proc 312

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!