Tuesday, 13 March 2012

Solaris - scheduled prstat & vmstat jobs

We had a need to run a scheduled hourly run of prstat & vmstat for one of our suppliers to assist in troubleshooting.

1) The output would sent to a log file which would be appended too.
2) The programs would run for approx 1 minute.

Two scripts were written:

prstat script:
#!/usr/bin/ksh
echo "`date` : Start ------------------------"
/usr/bin/prstat -ca

echo "`date` : End ------------------------"
NOTE: prstat can't be configured to only for a set amount of runs/time.

vmstat script:
#!/usr/bin/ksh
echo "`date` : Start ------------------------"
/usr/bin/vmstat 5 12

echo "`date` : End ------------------------"
NOTE: vmstat has been set to run at 5 second intervals for 12 times.

crontab entries:
# prstat scheduled task
00 09 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
00 10 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
00 11 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
00 12 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
00 13 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
00 14 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
00 15 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
00 15 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
00 16 * * 2-5 /export/home/<account>/<script> >>/tmp/prstat.out
# vmstat scheduled task
00 09 * * 2-5 /export/home/<account>/<script> >>/tmp/vmstat.out
00 10 * * 2-5 /export/home/<account>/<script> >>/tmp/vmstat.out
00 11 * * 2-5 /export/home/<account>/<script> >>/tmp/vmstat.out
00 12 * * 2-5 /export/home/<account>/<script> >>/tmp/vmstat.out
00 13 * * 2-5 /export/home/<account>/<script> >>/tmp/vmstat.out
00 14 * * 2-5 /export/home/<account>/<script> >>/tmp/vmstat.out
00 15 * * 2-5 /export/home/<account>/<script> >>/tmp/vmstat.out
00 16 * * 2-5 /export/home/<account>/<script> >>/tmp/vmstat.out
# automatically kill prstat scheduled
01 09 * * 2-5 /usr/bin/pkill -x -u <account> prstat
01 10 * * 2-5 /usr/bin/pkill -x -u <account> prstat
01 11 * * 2-5 /usr/bin/pkill -x -u <account> prstat
01 12 * * 2-5 /usr/bin/pkill -x -u <account> prstat
01 13 * * 2-5 /usr/bin/pkill -x -u <account> prstat
01 14 * * 2-5 /usr/bin/pkill -x -u <account> prstat
01 15 * * 2-5 /usr/bin/pkill -x -u <account> prstat
01 16 * * 2-5 /usr/bin/pkill -x -u <account> prstat

NOTE: pkill had to be used to kill the prstat.

No comments:

Post a Comment