Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scripting help required. 1

Status
Not open for further replies.

ngtho

Technical User
Sep 28, 2001
1
0
0
CA
Hi guys, I'm a newbie to the UNIX OS, I need to know if I can write scripts to automate commands and if I can, how would I do it...

I need to take CPU and memory utilization readings (as well as other commands, such as iostat, mpstat, vmstat, etc) of the UNIX box every 10 seconds or so... dump those readings into a text file for graphing, etc.

Does anyone know if there is a utility that already does this? If not, does anyone have any sample scripts that I can view?

Thanks
 
Have you looked at 'sar' the system activity reporter ? This will produce all the stats you need, but it is complex and needs studying to interpret the results. If switched on, sar runs by default every ten minutes and stores results on a daily basis. Be wary of running something like this every 10 seconds - if you write this to a log file it will grow very quickly.
 
Good Afternoon ngtho,

I do use a very simple script to check one of our boxes, it's nothing special but it might point you in the right direction. You can add other commands and or send the output to temp files as well as your screen. (Please note this script will continuously loop until you break). Create your file with chmod 755 filename then simply run it: -

#!/bin/sh
clear
rm temp temp2
# Script to monitor virtual memory, real memory, cpu usage TCP connections and file system full -
#
while [ 1 ] #

do # start loop
echo "Your hostname is" ` hostname`" Last"`who -b|cut -c10-40`
uptime
echo

# will monitor the system specifically for Memory Usage and idle CPU % via vmstat and display stats
vmstat 10 5 >> temp # run vmstat 5 times every 10 seconds

date
echo
#
#
sed -e '1,3d' -e '/procs/,/id/d' temp >> temp2 # will remove 3 lines of headings each time they occur, starting at line 1
cat temp2|awk '{printf(" SWAP %s FREE Memory %s No. Scans %s Avail-CPU %s\n",$1, $4, $12, $22"%")}'

echo "******************************************************************************"
echo
/usr/ucb/ps -auxceg|head -25
echo "******************************************************************************"
echo
dmesg|grep full
iostat -xtc 10 3 # run iostat 3 times every 10 seconds
echo `netstat -a |grep ESTAB|wc -l `" Established Port Connections"
done # end of loop, returns to [ 1 ]


That's it. hope this helps

Marrow
 
Buy the following book if your really want to learn shell programming:

KornShell Programming Tutorial Barry Rosenberg (Addison Wesley Publishing) ISBN 0-201-56324-X

I have used it and trained junior programmers with it, we call it "the bible"

Steve B.
 
Alternatively, do a web search for shelldorado, a very useful site for beginners and experts alike. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top