homepage Welcome to WebmasterWorld Guest from 54.226.80.55
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
HTTP detection and memory detection from Linux shell
ooen




msg:907534
 9:23 pm on Dec 30, 2005 (gmt 0)

I'd like to do two things for a reason.

1. I'd like to detect if HTTP is accessible from Linux shell, and I'd like to know what script I need to write to do this.

2. I'd like to detect how much memory that the server is using from Linux shell, and I'd like to know what script I need to write to do this.

I'd appreciate any help.

 

rharri




msg:907535
 8:33 pm on Dec 31, 2005 (gmt 0)

I'm not sure about #1 but "top" from the command line should show all processess and the amount of memory they are using.

wheel




msg:907536
 8:33 pm on Dec 31, 2005 (gmt 0)

I'm not quite sure what your trying to accomplish, but from the command prompt, this should likely tell you if httpd is running:

ps aux¦grep httpd

and this will tell you what's up with memory:

cat /proc/meminfo

ooen




msg:907537
 8:38 pm on Jan 1, 2006 (gmt 0)

> ps aux¦grep httpd
I cannot use this because ...

I'd like to check http from command line for 10 seconds or so. To be more specific, I'd like to check if http is really responsive, useful and returning actual data in text to users. I found that I can use one of the following commands or both to do this

"GET /" ¦ nc localhost 80


curl http://www.myDomain.com/

However, running these commands when Apache is hanging doesn't really do anything. These commands just hang because Apache is neither completely down, nor is it responding properly. I'd like these commands to wait for 10 seconds or so and get whatever data returned. How do I do this?

wheel




msg:907538
 4:05 pm on Jan 2, 2006 (gmt 0)

Best bet is to subscribe to a monitoring service that emails you whenever your server is down. That's what you're trying to accomlish right?

A monitoring service is going to tell you a lot more than just whether apache is down. It can tell you if your connectivity is down, your nameservers, your email, etc etc etc. And of all those, apache is the last thing I'd expect to have problems. And I'd bet there are monitoring programs you can download for free and run on your own PC.

If you've got problems with apache not responding, you've got other problems that should be fixed. Apache just doesn't go down. The only reason I can think of for apache taking 10 seconds to respond would be under intense server load - and there are better and more reliable ways to monitor this than running a shell script.

(In other words, I'd recommend approaching this problem from a different angle than a shell script that tests if apache responds withing 10 seconds).

ooen




msg:907539
 8:55 pm on Jan 2, 2006 (gmt 0)

> Best bet is to subscribe to a monitoring service that emails you whenever your server is down. That's what you're trying to accomlish right?

...

> If you've got problems with apache not responding, you've got other problems that should be fixed. Apache just doesn't go down. The only reason I can think of for apache taking 10 seconds to respond would be under intense server load - and there are better and more reliable ways to monitor this than running a shell script.

> (In other words, I'd recommend approaching this problem from a different angle than a shell script that tests if apache responds withing 10 seconds).

I understand what you're saying, but I have not been able to solve the problem for some time now, and I really need a temporary solution to mitigate downtime. I was thinking about writing a shell script to do that, and this is why I was asking about

"GET /" ¦ nc localhost 80
curl [myDomain.com...]
etc.

I looked up other resources and I also tested different commands to see how they work. Now, I have the following shell script, which is a working progress.

#!/bin/bash
# My first script
LOGFILE="/home/admin/cron/http_log"

STATUS=`curl localhost --max-time 10`
if [ -z "$STATUS" ]; then
echo "Restart Apache"
/etc/rc.d/init.d/httpd restart
fi
echo $STATUS >> $LOGFILE

The purpose of the script is to restart Apache when it hangs or locks up.

One thing that I'd like to do is to write the output of httpd to log file, so that in case that something goes wrong, I can see what happened. How do I do that? Also how do I write the timestamp to log file? Also how does the script look in general?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved