Recipe 18-2: CSV Formatting

Systems administration is often very reactive, and there often isn’t time to design, write, and test a clean and tidy shell script. This recipe deals with a memory leakage problem; sometimes the best solution in this situation is to create a very quick and simple script that grabs the relevant data to be analyzed later. The important thing is to get timely data, not how tidy or nicely formatted the data (or even the script) is. grab-meminfo.sh is an example of such a script; it simply grabs the timestamp and a copy of /proc/meminfo three times a minute. It is better to save more data than you need than to discard details that will later be useful.

Technologies Used

  • /proc/meminfo
  • ((suffix++))
  • CSV
  • bc

Concepts

/proc/meminfo is one of many files under /proc that appear to be text files but are actually a direct interface to the current running Linux kernel. These are an excellent resource for shell scripts to acquire raw data from the kernel in an easy-to-use format, without relying on additional utilities (such as free), which take the same data and reinterpret it.

The plot-graph.sh script takes the raw data from /proc/meminfo and formats it into a CSV file, which can be read by spreadsheet software such as Microsoft Excel, OpenOffice.org, or LibreOffice. This desktop software can be used to format the data into a graph, which can help to visualize the memory usage over time. It also saves the data out in a more concise format. Finally, stats.sh uses ...

Get Shell Scripting: Expert Recipes for Linux, Bash, and More 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.