Sar data collection script for Unix and Linux


This script has written to check system “sar” data collection. Sar data collection can be useful to check system performance statistics for a specific time period. You only need to configure “sar” to collect performance statistics with a crontab job.

Sar can be used to collect performance data, redirect them, and perform historical analysis to identify performance bottlenecks.

Script  content:

  • Starting  sar service  on Oracle  Solaris server.
  • Adding sar line to sys or root user crontab file.
  • Creating  /var/adm/sa directory  if  it doesn’t exist.

Supported  Operating  Systems:

  • Oracle  Solaris
  • HP-UX
  • Red Hat 5-6
#!/bin/ksh
SOLARIS_SAR() {
if svcs svc:/system/sar:default |/usr/xpg4/bin/grep -q online >/dev/null 2>&1
then
DEG=`echo "Online"`
if cat /var/spool/cron/crontabs/sys|grep -v #|grep sa |grep -q sa1 >/dev/null 2>&1
then
echo "0,5,10,15,20,25,30,35,40,45,50,55 * * * 0-6 /usr/lib/sa/sa1" >>/var/spool/cron/crontabs/sys
echo "59 23 * * 0-6 /usr/lib/sa/sa2 -A" >>/var/spool/cron/crontabs/sys
fi
else
svcadm enable svc:/system/sar:default
if cat /var/spool/cron/crontabs/sys|grep v #|grep sa |grep -q sa1 >/dev/null 2>&1
then
echo "0,5,10,15,20,25,30,35,40,45,50,55 * * * 0-6 /usr/lib/sa/sa1" >>/var/spool/cron/crontabs/sys
echo "59 23 * * 0-6 /usr/lib/sa/sa2 -A" >>/var/spool/cron/crontabs/sys
fi
DEG=`echo "Started"`
fi
}

LINUX_SAR() {

if cat /etc/cron.d/sysstat|grep sa |grep -q sa1 >/dev/null 2>&1
then
if cat /etc/cron.d/sysstat|grep sa |grep -q sa2 >/dev/null 2>&1
then
DEG=`echo "Online"`
else
echo "53 23 * * * root /usr/lib64/sa/sa2 -A" >> /etc/cron.d/sysstat
DEG=`echo "Started"`
fi
else
echo "*/10 * * * * root /usr/lib64/sa/sa1 1 1" >> /etc/cron.d/sysstat
if cat /etc/cron.d/sysstat|grep sa |grep -q sa2 >/dev/null 2>&1
then
DEG=`echo "Online"`
else
echo "53 23 * * * root /usr/lib64/sa/sa2 -A" >> /etc/cron.d/sysstat
DEG=`echo "Started"`
fi
fi
}

HPUX_SAR() {
if cat /usr/spool/cron/crontabs/root|grep sa |grep -q sa1 >/dev/null 2>&1
then
DEG=`echo "Online"`
else
if [ -d /var/adm/sa ]
then
echo "0 * * * 0,6 /usr/lbin/sa/sa1" >> /usr/spool/cron/crontabs/root
echo "0 8-17 * * 1-5 /usr/lbin/sa/sa1 300 3" >> /usr/spool/cron/crontabs/root
echo "0 18-7 * * 1-5 /usr/lbin/sa/sa1" >> /usr/spool/cron/crontabs/root
DEG=`echo "Started"`
else
mkdir -p /var/adm/sa
echo "0 * * * 0,6 /usr/lbin/sa/sa1" >> /usr/spool/cron/crontabs/root
echo "0 8-17 * * 1-5 /usr/lbin/sa/sa1 300 3" >> /usr/spool/cron/crontabs/root
echo "0 18-7 * * 1-5 /usr/lbin/sa/sa1" >> /usr/spool/cron/crontabs/root
DEG=`echo "Started"`
fi

fi
}

OS=`uname -s`

case "$OS" in
"SunOS")
SOLARIS_SAR
printf "%-20s%-20s\n" "`hostname`" "$DEG"
;;
"Linux")
LINUX_SAR
printf "%-20s%-20s\n" "`hostname`" "$DEG"
;;
"HP-UX")
HPUX_SAR
printf "%-20s%-20s\n" "`hostname`" "$DEG"
;;
"AIX")
;;

esac

 

I'm a IT Infrastructure and Operations Architect with extensive experience and administration skills and works for Turk Telekom. I provide hardware and software support for the IT Infrastructure and Operations tasks.

205 Total Posts
Follow Me

0 Comments

Leave a Reply