Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question on Bash Shell Script for Load Performance Monitoring

0 views
Skip to first unread message

aixenv

unread,
Oct 24, 2004, 10:46:45 AM10/24/04
to
I am writing a script to monitor a server which has halted at a
strange hour with no visible reason, I have reason to suspect it could
be a runaway qmail process or the system is just getting under heavy
load, or both.

SO I wrote the following script, it works, it just seems very
"sloppy", and I was just curious how else I could accomplish the same
goal.

Also i thought of emailing the output of /tmp/srvload.log to an email
address and thought it might be nice to sort newest entries in
/tmp/srvload.log to the beginning of the file versus appending them to
the end of the file. however i am unclear how to proceed and
accomplish this goal

any assistance would be appreciated, below is said script.

#!/bin/bash

while
true
do
echo "" >> /tmp/srvload.log
echo "#############################" >> /tmp/srvload.log
echo "" >> /tmp/srvload.log
echo "The current time is `date`" >> /tmp/srvload.log
echo "" >> /tmp/srvload.log
echo "- Current system load average" >> /tmp/srvload.log
uptime >> /tmp/srvload.log
echo "" >> /tmp/srvload.log
echo "- The number of current qmail processes" >> /tmp/srvload.log
ps aux|grep qmail|wc -l >> /tmp/srvload.log
echo "" >> /tmp/srvload.log
echo "- The current number of Messages in the queue">>
/tmp/srvload.log
qmail-qstat >> /tmp/srvload.log
echo "" >> /tmp/srvload.log
echo "#############################" >> /tmp/srvload.log
echo "" >> /tmp/srvload.log
sleep 300
done

The mail script would be like so, perhaps there is a way to combine
both of these into 1 script

#!/bin/bash

while
true
do
echo "`cat /tmp/srvload.log`" | mail -s "Sysload.sh output"
mye...@mydomain.com
sleep 1800
done

thank you

aix

Michael Heiming

unread,
Oct 24, 2004, 1:06:41 PM10/24/04
to
In alt.os.linux aixenv <aix...@yahoo.com>:

> I am writing a script to monitor a server which has halted at a
> strange hour with no visible reason, I have reason to suspect it could
> be a runaway qmail process or the system is just getting under heavy
> load, or both.
[..]

> Also i thought of emailing the output of /tmp/srvload.log to an email
> address and thought it might be nice to sort newest entries in
> /tmp/srvload.log to the beginning of the file versus appending them to
> the end of the file. however i am unclear how to proceed and
> accomplish this goal

[..]

- You want to run something like this from cron every 5 minutes,
no need for sleep.

- You are over complicating things, easier should be to use "EOF",
adjust this example to your needs:

#!/bin/bash

FILE="/tmp/logfile"

cat >> $FILE << EOF

#############################


The current time is `date`

#############################
EOF

> echo "`cat /tmp/srvload.log`" | mail -s "Sysload.sh output"
> mye...@mydomain.com

You can put this simply below the script, dunno why you need
"echo" again.

Good luck

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: 0xEDD27B94)
mail: echo zvp...@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 238: You did wha... oh _dear_....

Dan Skinner

unread,
Oct 24, 2004, 4:56:48 PM10/24/04
to
aix...@yahoo.com (aixenv) wrote in message news:<d687f0.041024...@posting.google.com>...

> I am writing a script to monitor a server which has halted at a
> strange hour with no visible reason, I have reason to suspect it could
> be a runaway qmail process or the system is just getting under heavy
> load, or both.
>
> SO I wrote the following script, it works, it just seems very
> "sloppy", and I was just curious how else I could accomplish the same
> goal.
>
> Also i thought of emailing the output of /tmp/srvload.log to an email
> address and thought it might be nice to sort newest entries in
> /tmp/srvload.log to the beginning of the file versus appending them to
> the end of the file. however i am unclear how to proceed and
> accomplish this goal
>
> any assistance would be appreciated, below is said script.
<snip>
> thank you
>
> aix

A few suggestions:
1. Run your scripts from cron rather than loop and stagger run times.
2 Keep the logging and emailing in separate processes(scripts).
3. make your logger write a single line per event with the time at the
beginning of the line. Build up the line with a variable then echo out the
variable. Makes debugging and changing easier, beauty is not your goal.
4. pipe from sort rather than cat to mail the log file IE:
sort < logfile | mail -s"log subject" mail@address
or for reverse order
sort -r < logfile | mail -s"log subject" mail@address
You can make sort smarter if you must.
5. sar is your friend. Might be all you need.
Regards...Dan.

0 new messages