Timestamp vmstat

Here’s a script I wrote to timestamp vmstat for when you want to let vmstat run for extended periods of time

#!/bin/bash

if [ "$1" == "-h" ]; then echo "usage $0 [delay in seconds]"; exit; fi
if [ $# == "1" ]; then
        delay=$1
else
        delay=1
fi

#print every XX lines
print=30
i=0

while true; do
        date=`date +%m/%d\ %H:%M:%S`
        if [ $(($i % $print)) -eq 0 ]; then
                vmstat | while read line $l; do
                        echo "$date - $line"
                done
        else
                echo -n "$date -"
                vmstat | tail -n 1
        fi
        i=$(($i + 1))
        sleep $delay
done

No Comments Yet

Leave a Reply

Your email address will not be published. Required fields are marked *