Solved

vmstat format for mobile device

Posted on 2014-10-10
4
118 Views
Last Modified: 2014-10-14
Hi everyone,
I need to format vmstat , this script should format vmstat for easy reading on cell phones etc,  I am looking to send the output to email every three hours.

Output should look like this:

Sat Feb 18 11:15:48 PST 2012
1 processes are waiting
0 processes are blocked


Thank you!
0
Comment
Question by:Peter Kuczynski
  • 2
  • 2
4 Comments
 
LVL 19

Expert Comment

by:simon3270
ID: 40378408
There are many ways to format this, but I'd use awk:
#!/bin/bash

TMPF=/tmp/vm.$$

date > $TMPF

vmstat | tail -1 | awk '{print $1 " processes are waiting\n" $2 " processes are blocked"}' >> $TMPF

cat $TMPF | mail -s "vmstat output" fred@example.com

rm $TMPF

Open in new window


Then add
    0 */3 * * * /path/to/above/script.sh

The above assumes that all of the commands specified are in /bin or /usr/bin. since that's the PATH which will be used - if they aren't, put in the full path to the commands.
0
 
LVL 1

Author Comment

by:Peter Kuczynski
ID: 40378478
ok, let me give this a shot : )
0
 
LVL 1

Author Comment

by:Peter Kuczynski
ID: 40378653
Works great!
What if I wanted to add a log to this so it writes and keeps it for a week or so then starts a new one??
0
 
LVL 19

Accepted Solution

by:
simon3270 earned 500 total points
ID: 40380950
You could add this just before the "rm" comamnd:

    cat $TMPF >> /path/to/log/directory/vmstat_$(date '+%G-%V').log

This will write to a file such as

    /path/to/log/directory/vmstat_2014-42.log

In the "date" command, %V gives the ISO week number, and %G gives the year that the week is in (usually the same as the current year, but it varies a bit round New Year, I think).

So, it writes all of the data from one week (starting on a Monday) to a single file, then writes the next week's data to a new file and so on.  All you then have to do is to remove old files when you no longer need them.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
need some regex help 15 29
copy-item script help 15 78
AWS CLI - Instances, Volumes & Tagging 2 95
script issue to add permissions to the registry hive 2 39
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question