
how-to block ads
|
  technick Premium join:2000-12-16 Loganville, GA
| Mailserver Statistics Shell Script
I've gotta admit my script fu is very weak... Most of the time if I ever needed a program or app I would just look for something that someone has already made, etc. I've been doing some studying on script writing and well this is my first. Please be nice =).
This is designed to work on systems with Sendmail / ClamAV and depends on standard unix utils for the rest of the info. Here is the script if anyone else wants to use it or thinks they have a use for it. Very simple script...
Here is a sample output of it.
System Statistics v0.001a by Nicholas Winn Mon Dec 12 20:31:23 EST 2005 xxx.xxxxxxxxxxxxxxxxx.org inet addr:10.0.1.6 Bcast:10.0.1.255 Mask:255.255.255.0 inet addr:62.122.1.13 Bcast:62.122.1.65 Mask:255.255.255.240 ================================================================================== ============ procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r b swpd free inact active si so bi bo in cs us sy id wa 1 0 696 8728 133668 306792 0 0 7 36 2 14 1 0 98 0 ================================================================================== ============ Filesystem 1K-blocks Used Available Use% Mounted on /dev/hda2 11499944 1576984 9329360 15% / /dev/hda1 544596 24044 492440 5% /boot /dev/shm 253992 0 253992 0% /dev/shm /dev/hda5 24789348 206072 23303704 1% /home ================================================================================== ============ Dec 12 20:29:40 mailserver pop3-login: Login: db [::ffff:10.0.1.135] Dec 12 20:29:47 mailserver pop3-login: Login: vanessa [::ffff:10.0.1.12] Dec 12 20:29:50 mailserver pop3-login: Login: vaxt [::ffff:10.0.1.66] Dec 12 20:30:03 mailserver imap-login: Login: dgionfrio [::ffff:10.0.1.113] Dec 12 20:30:03 mailserver imap-login: Login: dgionfrio [::ffff:10.0.1.113] Dec 12 20:30:33 mailserver sendmail[15813]: jBD1UT5a015813: from=root, size=11083, class=0, nrcpts=1, relay=root@localhost Dec 12 20:30:47 mailserver pop3-login: Login: vanessa [::ffff:10.0.1.12] Dec 12 20:31:04 mailserver imap-login: Login: dgionfrio [::ffff:10.0.1.113] Dec 12 20:31:04 mailserver imap-login: Login: dgionfrido [::ffff:10.0.1.113] Dec 12 20:31:11 mailserver pop3-login: Login: fstock [::ffff:31.111.99.174] ================================================================================== ============ Dec 12 19:37:27 mailserver sendmail[9165]: jBD0bPJ9009165: Milter add: header: X-Virus-Status: Infected with Worm.Sober.U [root@mailserver ~]#
Here is the full script
while true do clear echo "System Statistics v0.001a by Nicholas Winn" date hostname ifconfig eth0 | tail -9 | head -1 ifconfig eth1 | tail -9 | head -1 echo "================================================================================== ============" vmstat -a echo "================================================================================== ============" df echo "================================================================================== ============" tail -10 /var/log/maillog echo "================================================================================== ============" cat /var/log/maillog | grep Infected | tail -1 sleep 1 done -- "Our greatest glory consists not in never falling, but in rising everytime we fall." - Confucius Bellsouth Free Since 10/05 - To Hell With Bellsouth
Advocatus Diaboli | |   BeesTea Network Janitor Premium,VIP join:2003-03-08 00000
| Nice work. A few things you could take advantage of.
ifconfig eth0 | tail -9 | head -1 could be
ifconfig eth0 | grep Bcast and,
cat /var/log/maillog | grep Infected | tail -1 could be
grep Infected /var/log/maillog | tail -n1 Finally, every where you have tail, head, etc, you should use -n1 and not -1 etc, -(number) is deprecated.
You might also wrap the whole thing into a single cat.
while true do clear
cat << EOF System Statistics v0.001a by Nicholas Winn `/bin/date` `/bin/hostname` `/sbin/ifconfig -a | grep Bcast` ================================================================================== ============ `/usr/bin/vmstat -a` ================================================================================== ============ `/bin/df` ================================================================================== ============ `tail -n10 /var/log/maillog` ================================================================================== ============ `grep Infected /var/log/maillog | tail -n1` EOF
sleep 1 done -- Captain of the ATU Tux Racer Clan. | |
|