Solved

vmstat format for mobile device

Posted on 2014-10-10
4
120 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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