# VMSTAT script / command help

**URL:** <https://community.unix.com/t/vmstat-script-command-help/211647>\
**Category:** Shell Programming and Scripting\
**Created:** [September 8, 2008, 12:18pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647 "2008-09-08T12:18:36Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![komputersman](https://community.unix.com/letter_avatar/komputersman/32/5_5575768a8748004e209b776fc1b2916d.png) [@komputersman](https://community.unix.com/u/komputersman)\
**Post date:** [September 8, 2008, 12:18pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/1 "2008-09-08T12:18:36Z")

</div>

Hello all, I know it can be done but don't know the command.

I would like to run vmstat via cron, I don't know a good interval and don't want huge logs but want stats pretty often.

Please someone who uses vmstat via cron let me know what your script looks like.

Thank you

---

<div class="post-metadata">

**Author:** ![Ikon](https://community.unix.com/user_avatar/community.unix.com/ikon/32/1015_2.png) [@Ikon](https://community.unix.com/u/Ikon)\
**Post date:** [September 8, 2008, 12:52pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/2 "2008-09-08T12:52:10Z")

</div>

We run this everymorning at 12:02 am:

vmstat 60 1440 \> /path/to/vmstat.`date +%d`

This will write to a file every minute for 24 hours then create a new file and start over.

We then have another script that summarizes the data and builds graphs and emails them everyday.

---

<div class="post-metadata">

**Author:** ![komputersman](https://community.unix.com/letter_avatar/komputersman/32/5_5575768a8748004e209b776fc1b2916d.png) [@komputersman](https://community.unix.com/u/komputersman)\
**Post date:** [September 8, 2008, 2:11pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/3 "2008-09-08T14:11:09Z")

</div>

Can you post or IM the other script too, a graph would be a cool visual feature. I am not sure what is required for it to run and display right but if I can I think id like to use it.

Thanks.

---

<div class="post-metadata">

**Author:** ![Ikon](https://community.unix.com/user_avatar/community.unix.com/ikon/32/1015_2.png) [@Ikon](https://community.unix.com/u/Ikon)\
**Post date:** [September 8, 2008, 2:18pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/4 "2008-09-08T14:18:48Z")

</div>

Its acutally a collection of several scripts. I import all the vmstat datainto a sql database and then have a whole website that builds the graphs (images) as requested using Perl GD:Graph Link:[GD::Graph - Graph Plotting Module for Perl 5 - search.cpan.org](http://search.cpan.org/~mverb/GDGraph-1.43/Graph.pm)

Here is a sample of the graph that is built:

![](https://community.unix.com/uploads/default/original/2X/c/c829f8bd6272622cb1d0a62853ca2e406ea4e0d7.gif)

GD:Graph is not a difficult module to use.

---

<div class="post-metadata">

**Author:** ![komputersman](https://community.unix.com/letter_avatar/komputersman/32/5_5575768a8748004e209b776fc1b2916d.png) [@komputersman](https://community.unix.com/u/komputersman)\
**Post date:** [September 8, 2008, 2:52pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/5 "2008-09-08T14:52:50Z")

</div>

> [@ikon](#):
>
> We run this everymorning at 12:02 am:

02 0 \* \* \* (path to script)

Is that correct?

> [@ikon](#):
>
> vmstat 60 1440 \> /path/to/vmstat.`date +%d`

For this to be a script it would be...

#/bin/bash  
vmstat 60 1440 \> /path/to/vmstat.`date +%d`

Is that right?

Sorry I am somewhat new to scripts and cron...

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![Ikon](https://community.unix.com/user_avatar/community.unix.com/ikon/32/1015_2.png) [@Ikon](https://community.unix.com/u/Ikon)\
**Post date:** [September 8, 2008, 3:04pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/6 "2008-09-08T15:04:34Z")

</div>

Yes that looks correct.

---

<div class="post-metadata">

**Author:** ![komputersman](https://community.unix.com/letter_avatar/komputersman/32/5_5575768a8748004e209b776fc1b2916d.png) [@komputersman](https://community.unix.com/u/komputersman)\
**Post date:** [September 9, 2008, 2:06pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/7 "2008-09-09T14:06:36Z")

</div>

> [@ikon](#):
>
> We run this everymorning at 12:02 am:
> 
> vmstat 60 1440 \> /path/to/vmstat.`date +%d`
> 
> This will write to a file every minute for 24 hours then create a new file and start over.

Where would this create the file? In the /path/to/vmstat? If so can I path it to another dir?

---

<div class="post-metadata">

**Author:** ![Ikon](https://community.unix.com/user_avatar/community.unix.com/ikon/32/1015_2.png) [@Ikon](https://community.unix.com/u/Ikon)\
**Post date:** [September 9, 2008, 2:15pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/8 "2008-09-09T14:15:25Z")

</div>

Put it whereever you want.

in this case it would be in /path/to/ with a filename of vmstat.01 (01 = date)

---

<div class="post-metadata">

**Author:** ![komputersman](https://community.unix.com/letter_avatar/komputersman/32/5_5575768a8748004e209b776fc1b2916d.png) [@komputersman](https://community.unix.com/u/komputersman)\
**Post date:** [September 9, 2008, 2:45pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/9 "2008-09-09T14:45:03Z")

</div>

OK I thought so, sorry for being over cautious.

One more question...  
I manually ran it to test and I got a file name of "vmstat.date +%d"

What in the code did I miss?

I have it like such...  
vmstat 60 1440 \>/home/user/vmstat/vmstat.'date +%d'

---

<div class="post-metadata">

**Author:** ![avronius](https://community.unix.com/letter_avatar/avronius/32/5_5575768a8748004e209b776fc1b2916d.png) [@avronius](https://community.unix.com/u/avronius)\
**Post date:** [September 9, 2008, 2:48pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/10 "2008-09-09T14:48:47Z")

</div>

you need to use the backtick (same key as ~) - not single quote

From:

```nohighlight
vmstat 60 1440 >/home/user/vmstat/vmstat.'date +%d'

```

To:

```nohighlight
vmstat 60 1440 >/home/user/vmstat/vmstat.`date +%d`

```

edit: to include the code

---

<div class="post-metadata">

**Author:** ![komputersman](https://community.unix.com/letter_avatar/komputersman/32/5_5575768a8748004e209b776fc1b2916d.png) [@komputersman](https://community.unix.com/u/komputersman)\
**Post date:** [September 9, 2008, 2:57pm UTC](https://community.unix.com/t/vmstat-script-command-help/211647/11 "2008-09-09T14:57:06Z")

</div>

Ahh yup that did it... thank you so much for your help this is exactly what I needed.

---

<div class="post-metadata">

**Author:** ![Michenux](https://community.unix.com/user_avatar/community.unix.com/michenux/32/4986_2.png) [@Michenux](https://community.unix.com/u/Michenux)\
**Post date:** [April 9, 2009, 10:54am UTC](https://community.unix.com/t/vmstat-script-command-help/211647/12 "2009-04-09T10:54:21Z")

</div>

Hi,

If you're interesting in drawing charts from vmstat log files,  
you should try vmstax. You upload your log files, the charts  
are built and then you export them as image(png).

[[http://www.michenux.net/vmstax-build-vmstat-charts-1.html](http://www.michenux.net/vmstax-build-vmstat-charts-1.html)]Vmstax | Michenux

😉
