Forum Moderators: bakedjake
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.
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/
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).
...
> 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
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?