?
Solved

vmstat format for mobile device

Posted on 2014-10-10
4
Medium Priority
?
125 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

770 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