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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I make a script to log the load every 5 minutes 2

Status
Not open for further replies.

linuxMaestro

Instructor
Jan 12, 2004
183
US
How do I make a script to log the load every 5 minutes?
 
man cron

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
First you need to sort out what load you want to measure. Check out the man pages for iostat, vmstat and netstat. For example, if you want to measure network loading, you could use netstat. This would give you 'Packets in' and Packets out' every 10 seconds :
while true
do
netstat -ilhme0|grep ^hme0|awk '{print $5"\t"$7}';sleep 10
done
... where your interface is hme0 - check that with ifconfig -a

If you want to schedule it, use cron as PHV suggests.
Also I think every 10 minutes won't give you a very good measure of what's happening - you need to look more frequently, and there's not much overhead involved.

hope it helps.
Mike
 
Another way:
man sar

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Another way, another example, in the form of a script:
Code:
#!/bin/ksh
#
LOG_FILE=/path/to/system_loading.log
FLAG_FILE=/path/to/loading_flagfile

touch ${FLAG_FILE}
while [[ -f ${FLAG_FILE} ]]
do
uptime >> ${LOG_FILE}
sleep 600
done

Run the script. When you want to kill it, just remove the flag file with:
rm -f /path/to/loading_flagfile

Further improvements could be made by date stamping the log file, so a new one is created every day.

I hope that helps and stimulates further thought.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top