Solved

vmstat format for mobile device

Posted on 2014-10-10
4
115 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
Comment Utility
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
Comment Utility
ok, let me give this a shot : )
0
 
LVL 1

Author Comment

by:Peter Kuczynski
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now