Koozali.org: home of the SME Server
Obsolete Releases => SME 7.x Contribs => Topic started by: purvis on June 10, 2009, 12:55:54 AM
-
Hi everyone !
Seems a few things are becoming more easier and some things are just getting harder and more difficult.
I have been running sme server as a server for some time now and i would like to try to automate a few things that for some of you out there is probably a piece of cake in the sme server linux world.
I do not have a list but most things would be in a linux environment.
Two things would be very helpful, get the disk redundacy status and server status(server uptime) into two individual text files. I guess an automated process by a cron method would be the best way to go. Hummm, i have no idea what a cron is but reason says it is a batch process that is run at a particular time or mutilple times of the day.
I have books on linux but it would be nice to have first a helping hand on something simple from this forum being it is going to run on a sme server.
So to start with something simple. Have every hour a program to report the server uptime into a text file then have the same text file copied to a directory where it can be read by a web browser. So the steps would be.
1.run a script at a particular time
2.script creates a directory if one does not exist to place the text file
3.script writes some information into the text files such as a heading for the server and current date and time
4.script runs some program to attain the server uptime and outputs the information into a text file
5.script creates a web directory to hold the text file if it does not exist.
6 script copies the text file created to the webpage directory
7 script ends
The second process would do something similiar, but get the disk redundacy status.
A later process could read the text files and do something, specially on the disk redundacy status if there where some problem showing, like maybe have a cron send an email to report a problem.
A good idea would also be a way of turning off a cron scripted program with a file being used as a flag to abort the script or email being sent.
I have been thinking about this for years and it is time act, now that todays phones have easy access to the web and we can be john on the spot when trouble come our way or we just want to check on processes remotely that usually have no security issues.
Thanks for any help on these subjects.
-
RAID status is emailed to you immediately it changes - why would you want anything else?
Why are you concerned about system uptime?
-
Charlie that is GREAT news but i have a problem with that in that emails are rarely read because there seems to be so much other insignificant emails coming from the servers, plus not all my servers are setup where i can easily get to the emails.
Even if they where emailed, it would seem i might want to choose different email accounts, etc, etc.
I also have windows workstations that read files from the server as well, and these computers can be setup to read files to tell if there is something wrong.
I have my reasons.
I have found the echo, date, uptime command. i just need help with the automation part that will give me a start.
-
Even if they where emailed, it would seem i might want to choose different email accounts, etc, etc.
You can choose to have the emails forwarded to any email account you nominate.
It seems that you haven't read the documentation very well. I suggest you read it at least twice more.
-
ok i created a script file called webstatus1 that creates the file "status1.prn" in a folder called "/home/e-smith/files/primary/html/serverstatus"
it writes this report that is easy to read on my iphone web browser ............
-------------------------------------------------------------
Server Status Report
Location: Management Office
Name: server0
Date of Report:
Tue Jun 9 22:38:49 CDT 2009
Uptime:
22:38:49 up 5:56, 1 user, load average: 0.00, 0.00, 0.00
Disk Redundacy Status:
Personalities : [raid1]
md2 : active raid1 sda2[0] sdb2[1]
245007232 blocks [2/2] [UU]
md1 : active raid1 sda1[0] sdb1[1]
104320 blocks [2/2] [UU]
unused devices: <none>
--end of report--
---------------------------------------------------------
the script to write the file and placedin the "/usr/sbin" directory
script name is "webstatus1"
----------------------------------------------------------------------------------------------------------
#!/bin/sh
mkdir /home/e-smith/files/primary/html/serverstatus
echo "Server Status Report" > /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "Location: Management Office" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "Name: server0" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "Date of Report:" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
date >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "Uptime: " >> /home/e-smith/files/primary/html/serverstatus/status1.prn
uptime >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "Disk Redundacy Status:" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
cat /proc/mdstat >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
echo "--end of report--" >> /home/e-smith/files/primary/html/serverstatus/status1.prn
-----------------------------------------------------------------------------------------------
Inside the /etc/cron.hourly directory i create a file with the command "echo > webstatus1".
Now i will pray it works.
-
It doesn't get much more simple than this. (This does need to run on a windows machine)
http://wiki.contribs.org/Netkeeper_Remote_Server_Monitor
-
Inside the /etc/cron.hourly directory i create a file with the command "echo > webstatus1".
Now i will pray it works.
Praying doesn't work. And neither will creating a webstatus1 file which contains nothing but a blank line.
Perhaps you mean:
echo /usr/sbin/webstatus1 > /etc/cron.hourly/webstatus1
Your script, BTW, will be more readable and maintainable if you do:
#!/bin/sh
mkdir -p /home/e-smith/files/primary/html/serverstatus
exec >/home/e-smith/files/primary/html/serverstatus/status1.prn
echo "Server Status Report"
echo
echo "Location: Management Office"
...
-
purvis good start and excellent concept.
Suggested Improvements.........sys_status.sh
#!/bin/sh
# ========= System Status ===================
clear
# Initialize variables
#f_path=/home/e-smith/files/primary/html/serverstatus
f_path=/tmp
f_name=status1.dat
location="Management Office"
server_name="Server 0"
# create & change to status directory if not exist
if [ ! -d $f_path ]; then
echo "===== MKDIR >>" $f_path
mkdir -p $f_path
fi
echo "===== CD >>" $f_path
cd $f_path
# server status
echo "Server Status Report" > $f_path/$f_name
echo "Location: " $location >> $f_path/$f_name
echo "Server Name: " $server_name >> $f_path/$f_name
echo "Snapshot Time: " `date` >> $f_path/$f_name
echo "Uptime: " `uptime` >> $f_path/$f_name
echo "*********** Raid Status ***********" >> $f_path/$f_name
cat /proc/mdstat >> $f_path/$f_name
echo "*********** Network Status ***********" >> $f_path/$f_name
ifconfig >> $f_path/$f_name
echo "--End of Report--" >> $f_path/$f_name
# Print the Status Report to the console
cat $f_path/$f_name
Go for it.... :smile:
hth
-
You could also add....
echo "*********** Drive/s Status ***********" >> $f_path/$f_name
df >> $f_path/$f_name
hth :smile:
-
@purvis and all: you don't need such a script..
yum install logwatch
man logwatch
regarding
in that emails are rarely read because there seems to be so much other insignificant emails coming from the servers
- there's no insignificant mails form the server and ignoring what server tell you could be a big error
- in case of raid failure you will receive a mail that you can't ignore
my 2c
Stefano
-
Just brain farting here a little, hth...
You could change this line
echo "Server Status Report" > $f_path/$f_name
to
echo "Server Status Report for $HOSTNAME" > $f_path/$f_name
hth & more fun
-
Stefano
You forgot to link to your wiki howto for logwatch.
-
@purvis and all: you don't need such a script..
They don't believe me - why would they believe you? :-)
-
They don't believe me - why would they believe you? :-)
Do believe you missed the OP's point.
-
They don't believe me - why would they believe you? :-)
"repetita iuvant", Charlie ;-)
-
"repetita iuvant", Charlie ;-)
Very Rude Post
-
Do believe you missed the OP's point.
so, please, explain to me OP's point.. as far as I understand, he wants something sending a mail if something goes wrong.. well, there's no need for it, because all you have to do is read the "insignificant" emails coming from the server..
then, please, help me to understand your answer to my post because it's late, I'm tired and my english comprehension may be faulty.
thank you
Stefano
-
Very Rude Post
why?
edit: electroman, please read here (http://en.wikiquote.org/wiki/Latin_proverbs#R), thank you
Stefano
-
I'm tired and my english comprehension may be faulty.
Stefano
Exactly.
This is an English forum, if you want to post in Spanish then use the Spanish forum.
Thanks for your rude post and derailing a very good thread topic.
You have a good day...
-
This is an English forum, if you want to post in Spanish then use the Spanish forum.
Stefano posted in Latin, and google was able to tell me it meant "repeated things help."
Thanks for your rude post and derailing a very good thread topic.
You have a good day...
I think if you really mean that you should lighten up a little.
OP is leading himself (and is being led) up the garden path, to think that a status web page will be more useful in the case of RAID failure than just reading the email notification which is already provided.
Nobody has yet told me why they want uptime notified.
-
OK
SOME OF YOU GUYS ARE AHEAD OF ME AND THAT IS FANTASTIC !!!
yes we did need the server name in a automatic fashion
yes we did need other other information that can be returned like uptime and mdstat
modifications need to be made it the "webstatus1" file script below and i will do that on a second edition of the script.
i am trying to keep this first server information page short so it can be viewed easily on a iphone or other device.
if it is keep short, it will make it easier for someone to review that does not have technical experience to read
the page from some browser.
i would like to a second report that contains much more information as possible about the server.
ok
here is what i have that is working to provide a uptime and disk raid status report
this should provide the easiest to follow procedure for others like me who are just getting
their feet wet and need to crawl before we walk.
a second version will come out but here is the first for the guys to keep things simple.
evolution is necessary.
a wish list in new versions of sme server would be to have a status folder like "/primary/html/servstat" and
have some information about the server placed into files upon bootup and/or an intermittent time scale.
instructions:
create two files and run the a command to update the system
create file "/usr/sbin/webstatus1"
---------------------------------
#!/bin/sh
mkdir -p /home/e-smith/files/primary/html/serverstatus
echo "Server Status Report" > /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "Location: Management Office" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "Name: server0" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "Date of Report:" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
date >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "Uptime: " >> /home/e-smith/files/primary/html/serverstatus/status1.txt
uptime >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "Disk Redundacy Status:" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
cat /proc/mdstat >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
echo "--end of report--" >> /home/e-smith/files/primary/html/serverstatus/status1.txt
create file "/etc/e-smith/templates/etc/crontab/custom1"
--------------------------------
*/5 * * * * root /usr/sbin/webstatus1
run this command
----------------
expand-template /etc/crontab
-
it will make it easier for someone to review that does not have technical experience to read
the page from some browser.
So you desire an htlm type page and/or pages?
-
Exactly.
This is an English forum, if you want to post in Spanish then use the Spanish forum.
Thanks for your rude post and derailing a very good thread topic.
I'm italian, I usually speak italian.. I guess your italian is as good as my english, is it?
You have a good day...
what part of "it's late" don't you understand?
Stefano and... it might be the crisis
-
i am trying to keep this first server information page short so it can be viewed easily on a iphone or other device.
if it is keep short, it will make it easier for someone to review that does not have technical experience to read
the page from some browser.
purvis, mails sent from server are in plain text; I read them with my phone (http://www.gsmarena.com/qtek_2020-1167.php) without problems
previuosly, I read them with a treo 270 smartphone...
you don't need any king of borwser, just a basic email client
Stefano and.. k.i.s.s. philosophy
-
it will make it easier for someone to review that does not have technical experience to read
the page from some browser.
So you desire an htlm type page and/or pages?
-
i am sorry about the code is not in blocks, i will learn.
I want to answer a few reasons of why i am doing this.
The first is email.
It is just fantastic when the server emails errors and status of things gone wrong, like a raid redundacy failure.
If emails are not read for one reason or the other, nobody is going to catch a big problem. I use to see all these notices about there where new updates or failures i thought where did not hurt overlooking, so i did not read emails.
A few of my machines are not setup where you can even get to the email from the internet.
My emails sent to outside accounts such as yahoo, have placed my email into JUNK/SPAM Folders because of the way our servers are setup on the internet.
I do not want to give a administrators password to every person or even a few people, a web service does not need a password.
I can write programs to download and read the webpages from anyplace without a password or be bothered with blocked service ports. Also i do not have to remember passwords to gain access to how a system is running. I am 52 now, what if i die or get hurt, i need others to fill in.
Simply put, by having information more easily to get to, a situation maybe found earlier, or information might be more easily gotten.
Ability to generate automatic emails are need along with the ability to forward emails, but many times in enviroments, it is simply overlooked or problems unforeseen cause us not to see or get a needed email notification.
I do appreciate the help i have gotten and i did not even know that an email would of been generated if the raid had failed.
TO THOSE OFFERING ADDITIONAL COMMANDS THAT DISPLAY SOME KIND OF STATUS FROM THE SERVER, PLEASE KEEP THEM COMING FOR A ADDITIONAL PROGRAM TO CREATE A SECOND WEBPAGE WITH SERVER STATUSES.
thank you
paul
-
purvis
Which one do you want emails or web pages, you already get admin email error status from sme.
I think what your after is this.
1 emails may not always be received, you may not be the admin.
2 you don't want all to have admin rights just to obtain the status.
3 you may request the info anywhere in the www from a browser or cell phone.
I think what your after is a small web that contains web pages for each desired status that anyone
that knows the secret link can view without a password possibly??
Senario....
Your a consultant and you do not want all admin emails from a 100 servers sent to you.
However your customer calls with a problem and you want to check the server status from your phone.
Certainly a viable concept.
I do have a script that does create a status html page, except it provides everything on 1 page.
hth
You can mod the script into multiple pages.
-
html page?
I like the plain text file, a html type page can read up the text file view it or a combination of text pages at one time.
Also i saw a php page a while back that would display some server information, it might of just been apache stuff, i do not remember.
I like the fact of a dynamic page as well in some php form, but i want to stay away from that for now. I know a lot of you guys are up on that stuff with the php code and that would be great, but again, i was concerned with the ability to easily read or copy a file with current information by other software. I also wanted to learn how to do some cron stuff.
I think a web viewable type page and/or pages is the first choice i had to place information retrieved, because there is a default ibay of primary already there and it could be easily read or copied to some others location as well.
I started out with .prn file but second thoughts led me to an .txt file, basically making it readable by many different sorts of programs.
------------------------------------
Hi Charlie,
On using the uptime program.
The uptime report is kool, it even tells us even the number of users on a server, WOW. Now, i can tell if any users are on the system before a reboot.
I find two things of importance that you may not. I like to have the dates and times of a boot on all computers, even a reboot is beneficial. The uptime gives me fast information from when the last time a boot occurred. I once even had to write a windows service program that keep up with how long a computer stays up and running. This is vital information when you are trying to solve for problems of various kinds. Maybe there is a power or electrical problem, a problem of somebody booting the computer and not telling you they are doing so , maybe you are interested in if a computer was running at certain times for various reasons, the list can not be preconceived most of the times, but the information is very helpful.
The logs of computers booting or just how long the computer is running and when it is running does not get big, even over years.
I have found this information just too valuable to be overlooked when it is needed and uptime time can be a handy source of information.
I did a little work on trying to create a log upon bootup that would write to a file of my choice but i am having problems there too.
Linux is just dandy if you know how to use it and i appreciate your hard unselfish work, sincerely, Paul.
-
Electroman,
Yes, you have been there.
This is all in house stuff for me, and not a hobby.
I have worried for years about a drive going down.
I plan on writing a program to read the webpage or file, at least on the drive redundacy status, then displaying the results if an error is detected also by users on windows workstations. My program can parse out the information.
I would be totally stupid to look a gift horse in the mouth, so yes, i am interested.
Being communication is becoming more and more with computers, i see a need with more servers, hence, the need for simple ways of checking them and by non-technical people as well.
thanks electroman
p.s.
I do not make money selling what i know, so that is the reason i was trying to do something on my own then if i posted it to share, it would not cause any hard feelings and i could give back some time to others that have given to me.
SO, IF YOU ARE NOT WILLING TO SHARE YOUR SCRIPT WITH THE WHOLE FORUM, WHICH IS PERFECTLY FINE AND I FULLY UNDERSTAND, I WOULD RATHER NOT SEE YOUR SCRIPT. IF YOU THINK ONLY A SMALL PART OF YOUR SCRIPT WOULD BE HELPFUL TO GET ME KICK STARTED, SPECIALLY IF IT PHP SCRIPT, I AM COULD USE THAT TO BUILD ON FOR A DYNAMIC STATUS WEBPAGE.
thanks again, paul
-
Just testing it now, will post when done 20 min or so.
-
Ok this is pretty basic on the fly.
#!/bin/bash
# System Status web page generator
##### Initialize variables
f_path=/home/e-smith/files/primary/html/serverstatus/
RIGHT_NOW=$(date +"%x %r %Z")
TIME_STAMP="Updated on $RIGHT_NOW by $USER"
##### Functions (all must preceed Main program code)
function system_info
{
echo "<h2>System release info</h2>"
echo "<p>Function not yet implemented</p>"
} # end of system_info
function show_uptime
{
echo "<h2>System uptime</h2>"
echo "<pre>"
uptime
echo "</pre>"
} # end of show_uptime
function show_raid
{
echo "<h2>Raid Status</h2>"
echo "<pre>"
cat /proc/mdstat
echo "</pre>"
} # end of show_uptime
function drive_space
{
echo "<h2>Filesystem space</h2>"
echo "<pre>"
df
echo "</pre>"
} # end of drive_space
function write_page1
# Write page in HTML format
{
TITLE="System Information for $HOSTNAME"
cat <<- _EOF_
<html>
<head>
<title>$TITLE</title>
</head>
<body>
<h1>$TITLE</h1>
<p>$TIME_STAMP</p>
$(system_info)
$(show_uptime)
$(drive_space)
$(show_raid)
</body>
</html>
_EOF_
}
function write_page2
{
# Write page in HTML format
TITLE="Raid Information for $HOSTNAME"
cat <<- _EOF_
<html>
<head>
<title>$TITLE</title>
</head>
<body>
<h1>$TITLE</h1>
<p>$TIME_STAMP</p>
$(show_uptime)
$(show_raid)
</body>
</html>
_EOF_
}
function write_page3
{
# Write page in text format .prn
TITLE="Raid Information for $HOSTNAME"
echo $TITLE
cat /proc/mdstat
}
##### Main Program Code
# create & change to status directory if not exist
if [ ! -d $f_path ]; then
echo "===== MKDIR >>" $f_path
mkdir -p $f_path
fi
# Write page (comment out until testing is complete)
filename=system_page.html
write_page1 > $fpath$filename
filename=raid_status.html
write_page2 > $fpath$filename
filename=raid_status.prn
write_page3 > $fpath$filename
Creates 3 files in f_path=/home/e-smith/files/primary/html/serverstatus/
system_page.html
raid_status.html
raid_status.prn
Could you imagine if I was good at this??
-
Now here's a problem with this, it's not dynamic data.
IOW the data is only relevant to the time stamp.
To make it dynamic you would need to change lang to Perl for example and write a wrapper to run the code on page load.
However this should get you started.
-
Well another way is javascript.
Whatever floats the boat. :smile:
-
Thanks, i have lots of boats living in Louisiana, USA and i can swim when i need to. lol
-
If you find yourself taking on water give a holler, we'll through you a life persevere.
Anyway did it work for ya?
-
Hey just found a booboo, last few lines.....
filename=system_page.html
write_page1 > $fpath$filename
filename=raid_status.html
write_page2 > $fpath$filename
filename=raid_status.prn
write_page3 > $fpath$filename
change to
filename=system_page.html
write_page1 > $f_path$filename
filename=raid_status.html
write_page2 > $f_path$filename
filename=raid_status.prn
write_page3 > $f_path$filename
Typing fast I missed the underscore in $fpath
Sorry bout that!!
Might just work now.
Also copy & paste this over the system_info function
function system_info
{
if ls /etc/redhat-release 1>/dev/null 2>&1; then
echo "<h2>System release info</h2>"
echo "<pre>"
for i in /etc/redhat-release; do
head -n 1 $i
done
uname -orp
echo "</pre>"
fi
} # end of system_info
-
I might add, the extension .prn is a windows print file extension, it is not a plain text file.
Therefore the code line
filename=raid_status.prn
should be changed to
filename=raid_status.txt
hth
-
ok here is what i have as far as a dynamic webpage using php
but i need a few more helpful jump starts from others.
i place some linux commands in here that are not necessary for a short webpage because i am so far playing around with it.
before i get myself in trouble, i could use some other useful commands to gather information but i have come a long way.
i would like to get some information such as the actual server name. if this php is run local(intranet), it does retrieve the server name but not if it is run from the internet.
my server's name is "server0" not "www.servername.com"
create your webpage file
maybe "serverstatus.php" in a web directory and point your browser to it from both the intranet and internet.
and i still like the cron program as well, i have not had time to try other programs placed into this thread because i am slow.
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->
<html>
<head><title>Server Status</title></head>
<body>
<b>
<tt>
<div>
<?php
print "<pre>";
print "Server Status Report\n";
print "Location: Management office\n";
print "URL name: ";
print ($_SERVER['SERVER_NAME']);
print "\n";
system("date | col -b",$return);
print "\n";
print "***** UPTIME ***************\n";
system("uptime | col -b",$return);
print "\n";
print "***** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print "\n";
print "***** DISK STATUS **********\n";
system("df -h | col -b",$return);
print "\n";
print "***** ETHERNET PORT STATUS ******\n";
system("ifconfig | col -b",$return);
print "\n";
print "*********************************\n";
system("uname -a | col -b",$return);
print "\n";
//print "***** RPM PACKAGES INSTALLED ****\n";
//system("rpm -qa --last | col -b",$return);
//print "\n";
//print "***** UPDATES FOR INSTALLED PACKAGES ****\n";
//system("yum list updates | col -b",$return);
//print "\n";
//print "*****************************\n";
//system("printenv | col -b",$return);
//print "\n";
print "\n---end of report---\n";
print "</pre>";
?>
</div>
</body>
</html>
-
OK...that's interesting.
Questions
Where is that page located on the server?
/home/e-smith/files/ibays/Primary/html/serverstatus
That page should not work located there.
If it does, then we have a major security problem with SME or you have foobar'ed SME security somehow.
-
Apparently you posted the code then the text as the edit, I saw the code stand alone.
Did you change any permissions on the system?
-
if this php is run local(intranet), it does retrieve the server name but not if it is run from the internet.
It shouldn't run any of the commands on that page from the internet.
If it does and you didn't make changes to SME permissions then there is a problem somewhere.
Have you changed any permissions on SME???
-
yes i did a chmod 777
i created a directory "/home/e-smith/files/primary/html/serverstatus"
then i did a chmod 777 to that directory
and yes i did post the code then the text prior to the code
i was learning the forum software to post correctly
-
OK I missed
create your webpage file
maybe "serverstatus.php" in a web directory and point your browser to it from both the intranet and internet.
When I opened it in my editor I saw the php tags.....da
Make sure that it has a .php and not .html (edit here >>) for the extension
I was very concerned if it ran externally with .html, then I tested it and .html doesn't work so all is ok.
Yea I forgot about running it php, you geared us to a local script from the start, so I went with the flow.
The php works fine.
i would like to get some information such as the actual server name.
HOSTNAME
Should be 755 or lower, 777 never used for externally facing pages.
Anyway it looks good....and works here.
-
my server's name is "server0" not "www.servername.com"
hostname = server0 (user defined name)
domain name = servername.com (requires external dns A record) for external access.
localhost = qualified default system name, qualified to the machine your working on.
hth
JFYI
The www tells your browser to start it's search externally and may or may not be required depending on the A record setup.
*.servername.com, A record will find www.servername.com or servername.com
www.servername.com, A record will find www.servername.com not servername.com, without an additional A record entry.
* = limited wildcard
-
ok try this
both a short report and a longer report
I tried to retain as much linux commands as possible because i wanted to learn linux commands such as "date" and not the php date functions. Later i will update my cron scripts that do something similiar and create a text file in the "serverstatus" directory.
It looks like i have the server name worked out too using the "uname -n" command.
my short report file name is "index.php"
this makes it easy to just go to "www.servername.com/serverstatus" for info
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->
<html>
<head><title>Server Status</title></head>
<body>
<tt>
<b>
<div>
<?php
print "<pre>";
echo '<font size="4">';
print "Server Status Report\n";
print "\n";
print "Current date : ";
system("date +'%m-%d-%Y %T %Z' | col -b",$return);
print " Location : Management office\n";
print " URL name : ";
print ($_SERVER['SERVER_NAME']);
print "\n";
print " Server name : ";
system("uname -n | col -b",$return);
$data = shell_exec('uptime');
$uptime = explode(' up ', $data);
$uptime = explode(',', $uptime[1]);
$uptime = $uptime[0].', '.$uptime[1];
$uptime = explode(',', $uptime);
print ('Hours uptime : '.$uptime[0].'');
print "\n";
print ('Active users : '.$uptime[1].'');
print "\n";
// print "***** UPTIME ***************\n";
// system("uptime | col -b",$return);
// print "\n";
print "\n";
print "***** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print "\n";
print "***** DISK STATUS **********\n";
system("df -h | col -b",$return);
//system("df | col -b",$return);
print "\n";
print "\n---end of report---\n";
print "</pre>";
?>
<p>A more detailed report is <a href="longreport.php">available here</a>.</p>
</div>
</body>
</html>
the long version needs to be named "longreport.php" on your server in the same directory as the above.
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->
<html>
<head><title>Server Status</title></head>
<body>
<tt>
<b>
<div>
<?php
print "<pre>";
echo '<font size="4">';
print "Server Status Report\n";
print "\n";
print "Current date : ";
system("date +'%m-%d-%Y %T %Z' | col -b",$return);
print " Location : Management office\n";
print " URL name : ";
print ($_SERVER['SERVER_NAME']);
print "\n";
print " Server name : ";
system("uname -n | col -b",$return);
$data = shell_exec('uptime');
$uptime = explode(' up ', $data);
$uptime = explode(',', $uptime[1]);
$uptime = $uptime[0].', '.$uptime[1];
$uptime = explode(',', $uptime);
print ('Hours uptime : '.$uptime[0].'');
print "\n";
print ('Active users : '.$uptime[1].'');
print "\n";
// print "***** UPTIME ***************\n";
// system("uptime | col -b",$return);
// print "\n";
print "\n";
print "***** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print "\n";
print "***** DISK STATUS **********\n";
// system("df -h | col -b",$return);
system("df | col -b",$return);
print "\n";
print "***** ETHERNET PORT STATUS ******\n";
system("ifconfig | col -b",$return);
print "\n";
print "***** SERVER TYPE ***************\n";
system("uname -a | col -b",$return);
print "\n";
//print "***** RPM PACKAGES INSTALLED ****\n";
//system("rpm -qa --last | col -b",$return);
//print "\n";
//print "***** UPDATES FOR INSTALLED PACKAGES ****\n";
//system("yum list updates | col -b",$return);
//print "\n";
//print "*****************************\n";
//system("printenv | col -b",$return);
//print "\n";
print "\n---end of report---\n";
print "</pre>";
?>
</div>
</body>
</html>
-
Cool....
You made the font larger.....yuck.
print "***** SERVER TYPE ***************\n";
system("uname -a | col -b",$return);
print "\n";
Cut that....and add this to top somewhere....
print "***** OS Info ***************\n";
system("uname -orp | col -b",$return);
print "\n";
Notice the uname options
-
i made a change in the above code to select a longer report.
notice the reference to another webpage at the bottom of index.php
-
our employees are getting old.
thanks for all your help
i believe this is something we can use, do you think.
i did like the uptime parameters giving some kind of server performance figures though.
good night
i will run this on my mac at home and see how it looks
maybe there needs to be a version that prints a larger font, ha ha.
-
well sure enough, the first server in at an off site location had an unclean raid1 array.
reviewing options now while backing up
-
i had the same problem as smeusr in a post here
http://forums.contribs.org/index.php/topic,44094.0.html
He reported this below on this forum
Hi, I just checked the health of my mirrored drives from the console and I got the following read out.
-----------------------------------------
Personalities : [raid1]
md2 : active raid1 sdb2[1]
312464128 blocks [2/1] [_U]
md1 : active raid1 sda1[0] sdb1[1]
104320 blocks [2/2] [UU]
unused devices: <none>
a reply said to do this to correct the issue
mdadm -a /dev/md2 /dev/sda2
it corrected my problem, now i have this result form my php program above index.php on directory "/primary/serverstatus"
Server Status Report
Current date : 06-15-2009 16:18:24 CDT
Location : Management office
URL name : www.myurlserver.com
Server name : server2
Hours uptime : 14:27
Active users : 0 users
***** RAID STATUS **********
Personalities : [raid1]
md2 : active raid1 sda2[0] sdb2[1]
312464128 blocks [2/2] [UU]
md1 : active raid1 sda1[0] sdb1[1]
104320 blocks [2/2] [UU]
unused devices:
***** DISK STATUS **********
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/main-root
292G 44G 233G 16% /
/dev/md1 99M 41M 53M 44% /boot
none 442M 0 442M 0% /dev/shm
---end of report---
A more detailed report is available here.
i was also able to easily monitor my raid rebuild about 70 miles, being i was working all night doing a backup, i did some remote control on the server by having a windows pc setup to manage the sme server and provide daily backups.
the rebuild took about 80 minutes.
Once other people got to the office this morning from a weekend, i showed them how to monitor the rebuild while i slept. This is the thing i was talking about earlier when you can never perceive the usefulness of something the serverstatus web pages i created with help from many of you. To have somebody help monitor the rebuild status and also include the staff watching the rebuild, it sure made things easier for the acceptance of what was going on and a acceptance for the staff not to do any work until the rebuild was done. I was able to monitor the rebuild on my iphone as well, kool.
-
purvis
....and a acceptance for the staff not to do any work until the rebuild was done...
A degraded array is still functional.
An array being resynchronised is also still functional, and in either case the server can still be used by users.
-
Thanks Mary
The degraded array has gone on for 10 months, since September 3,2008. Gustav hurricane. No telling what actually happened with the power. Now the raid status is being monitored. A nice web browser home page is what 2 users are getting.
-
@purvis
Thanks for this - I'd buy you more than one beer if you lived in my neighborhood :)
- this is such a handy php script!!
Glad I stumbled across it.
Cheers,
-
This thread to refers to add-on software.
Moving to contribs section as requested.
-
I would like to report back on my progress here with getting a report of the RAID1 condition and a few other things, such as files open in a SMB connection.
To get the condition of a raid array on the sme server.
First, i built some bash scripts to create some txt files periodically that had information in them i wanted and place them into a webpage file. I started using file extensions of .PRN then changed to .TXT file extensions. It was a learning experience for me as a beginner with linux, and where i as a user(admin) has to copy procedures to get things going.
But is soon found out how to use some simple php code to generated what i wanted into a web page servered by the sme server, which was far better and simpler.
I created a directory under the primary ibay called "'/home/e-smith/files/ibays/Primary/html/serverstatus"
I placed into the directory three php files that would run linux system commands and php commands to return minimum information, but important to me.
I used the chmod program to set the whole serverstatus directory to 777 which Charlie mentioned was some kind of security issue, then i believe somebody mentioned 775. I think now i understand Charlie's concern but i have not had time to work with chmod command and i needed to get things a rolling on to get the job done, but i want to come back to the chmod 777 thing some time soon.
I like having the directory name set to serverstatus for reasons it makes it easier to set some policies on windows clients using IEURLLOCK to access the web server but that is another story.
All this has come from help from others but i would like to wrap it up here with the three php files i am now using.
"lgreport.php" is just an extended and more detailed report than what the first report "index.php" reports on. I am using index.php as the short report because i do not want anybody browsing my web page directory "serverstatus". Who knows what i will put in there later. I also built a php file to report smb workstations longed on and open files on the server. This has been a big help in troubleshooting files left open with a little thing call "opportunistic file locking" and also just viewing what files are open and by whom for various other reasons. Do you know how hard it is to get files the opened and by who on a windows computer easily?
Naturally, like most users, we are running windows workstations. Here is how i am the using the web pages.
On the workstations, i created a directory called "C:\WEBPAGES", and placed two url shortcuts in the directory.
serverstatus.url
[InternetShortcut]
URL=http://192.168.1.191/serverstatus
filesopen.url
[InternetShortcut]
URL=http://192.168.1.191/serverstatus/sambausersopen.php
i have a batch file on every computer that performs all the setup after bootup
I placed the command "START C:\WEBPAGES\SERVERSTATUS.URL" as one of the last commands in my batch file.
Now upon any bootup from a windows workstation, which should be done daily in the morning, the users can study the reports for a bad raid array and low disk space useage.
I placed a shortcut to the directory "C:\WEBPAGES" on each users desktop so that anybody could easily get to the webpages. Sure is better than favorites and can be used with any web browser.
Here are the php files i use and i left some extra code in there for testing that is commented out with "\\" characters that may or may not be useful to others.
index.php
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->
<html>
<head><title>Server Status</title></head>
<body>
<tt>
<b>
<div>
<?php
print "<pre>";
echo '<font size="4">';
print "Server Status Report\n";
print "\n";
print "Current date : ";
system("date +'%m-%d-%Y %T %Z' | col -b",$return);
print " URL name : ";
print ($_SERVER['SERVER_NAME']);
print "\n";
print " Server name : ";
system("uname -n | col -b",$return);
print "************** UPTIME ***************\n";
system("uptime | col -b",$return);
print "\n";
print "\n";
print "************** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print "\n";
print "************** DISK STATUS **********\n";
system("df -h | col -b",$return);
//system("df | col -b",$return);
print "\n";
print "\n---end of report---\n";
print "</pre>";
?>
<p>A more detailed report is <a href="lgreport.php">available here</a>.</p>
</div>
</body>
</html>
lgreport.php
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->
<html>
<head><title>Server Status</title></head>
<body>
<tt>
<b>
<div>
<?php
print "<pre>";
echo '<font size="4">';
print "Server Status Report\n";
print "\n";
print "Current date : ";
system("date +'%m-%d-%Y %T %Z' | col -b",$return);
print " URL name : ";
print ($_SERVER['SERVER_NAME']);
print "\n";
print " Server name : ";
system("uname -n | col -b",$return);
print "************** UPTIME ***************\n";
system("uptime | col -b",$return);
print "\n";
print "\n";
print "************** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print "\n";
print "************** DISK STATUS **********\n";
// system("df -h | col -b",$return);
system("df | col -b",$return);
print "\n";
print "************** ETHERNET PORT STATUS ******\n";
system("ifconfig | col -b",$return);
print "\n";
print "************** SERVER TYPE ***************\n";
system("uname -orp | col -b",$return);
print "\n";
print "************** SERVER MEMORY *************\n";
system("free | col -b",$return);
print "\n";
// print "************** RPM PACKAGES INSTALLED ****\n";
// system("rpm -qa --last | col -b",$return);
// print "\n";
// print "************** UPDATES FOR INSTALLED PACKAGES ****\n";
// system("yum list updates | col -b",$return);
// print "\n";
// print "**************************************************\n";
// system("printenv | col -b",$return);
// print "\n";
print "\n---end of report---\n";
print "</pre>";
?>
</div>
</body>
sambausersopen.php
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->
<html>
<head><title>Server Status</title></head>
<body>
<tt>
<b>
<div>
<?php
print "<pre>";
echo '<font size="4">';
print "Server Status Report\n";
print "\n";
print "Current date : ";
system("date +'%m-%d-%Y %T %Z' | col -b",$return);
print " URL name : ";
print ($_SERVER['SERVER_NAME']);
print "\n";
print " Server name : ";
system("uname -n | col -b",$return);
print "************** UPTIME ***************\n";
system("uptime | col -b",$return);
print "\n";
print "\n";
print "************** SMB STATUS ****************\n";
system("smbstatus | col -b",$return);
print "\n";
print "\n---end of report---\n";
print "</pre>";
?>
</div>
</body>
</html>
I had copied some code in the program to format the uptime information to something better, but it just did not work, so now i am coping out the return code of whatever sme server returns.
I do not know much about linux and somethings are very wierd, but i am finding out one thing. In linux "EVERTHING IS A FILE"
Now, at my office i can write a program to access these web pages one after another by either a web browser or a program i write to retrieve the web pages with a program to interpret the pages for my use.
-
it would be nice to get the command smartctl to run from a php script, but the test i have done report a permission problem.
one command, "smartctl -i /dev/sda" and "smartctl -i /dev/sdb" would show the raid1 drives serial number and help to identify the drive when a problem is detected.
there are other command such as "smartctrl -H /dev/sd?" does a quick test of the drives too.
Maybe somebody knows how to make it where these programs can be run from a php script.
<!--DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"-->
<html>
<head><title>Hard Drive Test</title></head>
<body>
<tt>
<b>
<div>
<?php
print "<pre>";
echo '<font size="4">';
print "\n";
print "***** RAID STATUS **********\n";
system("cat /proc/mdstat | col -b",$return);
print "\n";
print "***** DISK STATUS **********\n";
system("df | col -b",$return);
print "\n";
print "********** dev/sda information **********\n";
system("smartctl -i /dev/sda | col -b",$return);
print "\n";
print "*** quick smartdrive test on dev/sda *****\n";
system("smartctl -H /dev/sda | col -b",$return);
print "\n";
print "</pre>";
?>
</div>
</body>
</html>
Thanks in advance.
paul