Appendix A. A Complete Example

Peek is a fun and useful example of what shell scripts can do. A resource monitoring and troubleshoot script, peek sleeps for 20 or 30 seconds. Upon waking, it checks (or “peeks at”) system statistics using commands such as free and vmstat, and draws graphs representing the computer activity. Across the top of the display is the time of the last update, and the actual CPU and memory usage. Below the graphs, warnings appear about potential problems or bottlenecks.

Because the format of commands such as vmstat changes over time, the script might have to be modified for certain distributions. This version was designed for Red Hat 7.3. Figure A.1 shows peek in action.

Figure A.1. peek.sh.

The full source code appears in ...

Get Linux Shell Scripting with Bash now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.