#!/bin/sh # # This script records "vmstat" information for a defined period of time, # (default of 1 day) and records it to a file with a time stamp for each # line. when the script is done running each day, it compresses the log file. # # This script would typically be called from cron at just after midnight # each day. # # Usage: USEAGE="vmlog [-i interval] [-c count] [-l logfile]" # # Logfile - If not specified, this defaults to /var/tmp/vmlog with a # date and time stamp appended to the end. # Interval - If not specified, this defaults to 60 seconds. # Count - If not specified, this defaults to 24 hours worth of # observations, the number of which depends on the interval # chosen. # # Andy Welter # www.the-welters.com # 9/28/98 # if [ $# -eq 1 ]; then echo $USAGE exit 1 fi while [ $# -ge 2 ]; do case $1 in -c) COUNT=$2 shift 2 ;; -i) INTERVAL=$2 shift 2 ;; -l) LOG=$2 shift 2 ;; *) echo $USAGE exit 1 ;; esac done if [ -z "$INTERVAL" ]; then INTERVAL=60 fi if [ -z "$COUNT" ]; then # Number of seconds in a day = 24x60x60=86400 COUNT=`expr 86400 / $INTERVAL` fi if [ -z "$LOG" ]; then LOG=`date +"/var/tmp/stats/vmlog.%y%m%d"` else LOG=`date +"$LOG.%y%m%d"` fi vmstat $INTERVAL $COUNT | while read LINE; do date +"%H:%M:%S $LINE" >> $LOG done compress $LOG