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
> 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_....
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.