#!/bin/bash # cpu_watcher.sh # Meryll Larkin 2014-11-26 # logging for mpstat -P ALL # cron # min hr dy mo dow command # 0,20,40 * * * * /root/bin/cpu_watcher.sh # logdir="/root/bin/CPU_STATS" mkdir -p $logdir # we are collecting weekly statistics # this number is just going to be used to determine # file name (using modulus 7) # (date hyphen - do not use leading zero) day=`date +%-d | tr '\n|\r' ' '` mth=`date +%-m | tr '\n|\r' ' '` week=$((day % 7)) mo=$((mth % 3 + 1)) rm_mo=$(($mo + 1)) rm_mo=$(($rm_mo % 3)) # echo "week = $week" # echo "mo = $mo" # echo "rm_mo = $rm_mo" # remove cpu_stats from 3 months ago # so as not to fill up hd rm $logdir/cpu_stats_out$rm_mo* 2>/dev/null cpu_outfile="$logdir/cpu_stats_out$mo$week" { date /usr/bin/mpstat -P ALL echo '' echo '' } >> $cpu_outfile