Solved

vmstat format for mobile device

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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 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 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…

739 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