Aug.28

Solaris Script:- Generate sar CPU & MEMORY of current month

HI

This is to generate comma separated values of CPU and Memory usage of current month. later we can export to .csv file for plotting graph in excel.

 

#!/usr/bin/bash
#Wrote on 18-08-2016 by Ben George
##################################
# Generate sar CPU & MEMORY of current month
##################################
PATH=/usr/xpg4/bin:$PATH
IFS=$’\n’ read -d ” -ra date < <(ls -l /var/adm/sa/ | grep `date +%b` | awk ‘{print $6″ “$7}’)
IFS=$’\n’ read -d ” -ra file < <(ls -l /var/adm/sa/ | grep `date +%b` | awk ‘{print $9}’)
printf “\n\n##— CPU AVERAGE —## \n\n”
echo $(sar -u -f /var/adm/sa/sa01 | awk ‘NR==4{print “Date,”$2″,”$3″,”$4”,”$5}’)
for i in “${!date[@]}”
do
cpuvalues=$(sar -u -f /var/adm/sa/”${file[$i]}” | grep -i average | awk ‘{print $2″,”$3″,”$4″,”$5}’)
echo “${date[$i]},$cpuvalues”
done
printf “\n\n##— MEMORY AVERAGE —## \n\n”
echo $(sar -r -f /var/adm/sa/sa01 | awk ‘NR==4{print “Date,”$2”,”$3}’)
for j in “${!date[@]}”
do
memoryvalues=$(sar -r -f /var/adm/sa/”${file[$j]}” | grep -i average |awk ‘{print $2″,”$3}’)
echo “${date[$j]},$memoryvalues”
done

 

NOTE: please request if you have difficulty in copy/paste. i will send you script through mail

Share this Story:
  • facebook
  • twitter
  • gplus

About bentech4u

Comments(1)

  1. WL Choo
    2414 days ago

    Hi, I have difficulty copy and paste, could you please email me the scripts? TQ

Leave a Reply to WL Choo Cancel reply