[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

07/04/2009 at 11:11PM PDT, ID: 24544528
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.1

Shell Script to show the status of various linux daemons, interfaces and disk space in motd.

Asked by totalimpact in Bourne-Again Shell (bash), Bourne Shell (sh)

Tags: update-motd daemon status script

I am wondering if there are any pre-built shell scripts that show the status of common services, interfaces and disk space? I kind of have a start, but I was hoping there would be something freely available with nice formatting and all that.

I found this, and want to setup something similar on my Centos 5.3 server:
https://help.ubuntu.com/9.04/serverguide/C/update-motd.html

I downloaded the source, and I think I have it all ported to my platform, the only thing is my scripting skills are still very basic, i am choking on some areas. I wish it was better formatted, because theres still a couple of other items I  might add, and I am not sure if it will fit on one screen.

Specific status items I am looking for:
iptables
mysql
sendmail
webmin
samba
apache
sshd
df -h (show only the percentage free on /)
eth0 (UP? or DOWN?)
eht1 (UP? or DOWN?)
wlan0 (UP? or DOWN?)

Below is my rough draft
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
#!/bin/sh
#####Script to show status of daemons, interfaces and free disk space:
#########Apache status:
if [ -e /var/run/httpd.pid ]
then 
	echo "Webserver      	Online" > /etc/test.motd
else
	echo "Webserver      	Offline" >> /etc/test.motd
fi
#########MySQL status:
if [ -e /var/run/mysqld/mysqld.pid ]
then 
	echo "MySQL Database 	Online" >> /etc/test.motd
else
	echo "MySQL Database 	Offline" >> /etc/test.motd
fi
#########Sendmail status:
if [ -e /var/run/sendmail.pid ]
then 
	echo "Mailserver 	Online" >> /etc/test.motd
else
	echo "Mailserver 	Offline" >> /etc/test.motd
fi
#########Fail2ban status:
if [ -e /var/run/fail2ban/fail2ban.pid ]
then 
	echo "Fail2ban 	Online" >> /etc/test.motd
else
	echo "Fail2ban	Offline" >> /etc/test.motd
fi
#########SSHd status:
SSHSTAT=`/etc/init.d/sshd status |grep 'is running'`
if [ "$SSHSTAT" = "is running" ]
then 
	echo "SSH		 	Online" >> /etc/test.motd
else
	echo "SSH			Offline" >> /etc/test.motd
fi
#########Webmin status:
WEBMINSTAT=`/etc/init.d/webmin status |grep 'is running'`
if [ "$WEBMINSTAT" = "is running" ]
then 
	echo "Webmin		 	Online" >> /etc/test.motd
else
	echo "Webmin			Offline" >> /etc/test.motd
fi
##########Zaptel Status:
if [ -e /proc/zaptel/ ]
then 
	echo "Zaptel Trunks 	Online" >> /etc/test.motd
else
	echo "Zaptel Trunks Offline" >> /etc/test.motd
fi
#########Iptables status: 
FIREWALLSTAT=`/etc/init.d/iptables status`
if [ "$FIREWALLSTAT" = "Firewall is stopped." ]
then 
	echo "Firewall 	Offline" >> /etc/test.motd
else
	echo "Firewall 	Online" >> /etc/test.motd
fi
#########Eth0 status:
ETH0STAT=`ifconfig eth0 |grep UP | awk '{print $1}'`
if [ "$ETH0STAT" = UP ]
then 
	echo "LAN ETH0 	Online" >> /etc/test.motd
else
	echo "LAN ETH0  	Offline" >> /etc/test.motd
fi
#########Eth1 status:
ETH1STAT="ifconfig eth1 |grep UP | awk '{print $1}'"
if [ "$ETH1STAT" = UP ]
then 
	echo "LAN ETH1 	Online" >> /etc/test.motd
else
	echo "LAN ETH1  	Offline" >> /etc/test.motd
fi
#########Wlan0 status:
WLAN0STAT="ifconfig wlan0 |grep UP | awk '{print $1}'"
if [ "$WLAN0STAT" = UP ]
then 
	echo "Wireless 	Online" >> /etc/test.motd
else
	echo "Wireless  	Offline" >> /etc/test.motd
fi
#########Show percent used on root file system:
EXCLUDE_PARTITIONS="/auto/ripper|/dev/hda1|/dev/sda1|none|/dev/md0|/dev/md1|tmpfs|cdrom|Filesystem"
ROOTUSED=`df -H | grep -vE "^$EXCLUDE_PARTITIONS" | awk '{print $5 " " }' | sed 's/%//'`
if [ $ROOTUSED -gt 80 ]
then 
	echo "DANGER Disk space used: [31;47$ROOTUSED%" >> /etc/test.motd
else 
	echo "Disk space used: $ROOTUSED%" >> /etc/test.motd
fi
#########How many users are logged on:
echo "`who | wc -l` users are logged in" >> /etc/test.motd
 
Keywords: Shell Script to show the status of vario…
 
Loading Advertisement...
 
[+][-]07/13/09 11:21 AM, ID: 24842390

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/13/09 01:52 PM, ID: 24843806

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/13/09 04:01 PM, ID: 24844840

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07/14/09 12:51 PM, ID: 24853385

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/15/09 07:38 AM, ID: 24859879

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Bourne-Again Shell (bash), Bourne Shell (sh)
Tags: update-motd daemon status script
Sign Up Now!
Solution Provided By: mikelfritz
Participating Experts: 1
Solution Grade: B
 
 
[+][-]08/07/09 05:49 PM, ID: 25047797

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08/11/09 10:42 PM, ID: 25075968

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20090701_SELECT_ZONES