LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-05-2011, 10:59 AM   #1
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Rep: Reputation: 10
Bash Script to Monitor URL


Hi Friends,

In my company we are hosting web applications from our server Using Apache and Apache Tomcat. Is it possible to write "Bash script to Monitor The entire URL's " if possible means please guide me to write Script , I have basic ideas in bash script..

Thanks in Advance!!
V.Anish Kumar
 
Old 03-05-2011, 11:02 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,948

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by anishkumarv View Post
Hi Friends,
In my company we are hosting web applications from our server Using Apache and Apache Tomcat. Is it possible to write "Bash script to Monitor The entire URL's " if possible means please guide me to write Script , I have basic ideas in bash script..
Yes, very possible. We can "guide you" to go to http://www.google.com, and put in "bash scripting tutorial", and read some of them, if you don't know how to write a bash script. Also, read the man pages for the wget command.

And also, if you look it up, you'll probably also find many scripts that are already written, that you can look at and modify to suit you.
 
Old 03-05-2011, 09:13 PM   #3
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi TB0ne,

Ya thanks dude, I'll Try my level best :-)


Thanks in advance
Anish kumar.V
 
0 members found this post helpful.
Old 03-07-2011, 12:32 PM   #4
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi all,

using curl command how to monitor a website.
 
Old 03-07-2011, 01:32 PM   #5
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,822

Rep: Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347Reputation: 1347
When you say "Monitor a website" do you mean:

Make sure that the content of the website does not change

-or-

Make sure that the website is up and running
 
Old 03-07-2011, 04:12 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,948

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by anishkumarv View Post
Hi all,

using curl command how to monitor a website.
So, your "level best" meant asking the same question again?

And again, did you even try to look this up??? From a quick search for "linux curl website monitor bash script":
http://solutionexpertonline.com/2009...n-bash-script/
 
1 members found this post helpful.
Old 03-08-2011, 01:10 PM   #7
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi szboardstretcher & special thanks to TB0ne,


curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://google.com | awk '{for(i = 1; i<=NF; i++) if($i=="“totaltime:0.000n”“totaltime:0.000n”HTTP/1.1") print $(i+1);}'

Using this command i can able to get the HTTP error code.
using this code + with the help of conditonal statements i can able to write the script. but this is the right way to monitor the website using script, or any option is available??

@TB0ne : thanks for your link. with the help of that link i get some ideas :-)


Thanks in advance!!
Anish Kumar.V
 
Old 03-08-2011, 07:42 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,948

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by anishkumarv View Post
Hi szboardstretcher & special thanks to TB0ne,

curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://google.com | awk '{for(i = 1; i<=NF; i++) if($i=="“totaltime:0.000n”“totaltime:0.000n”HTTP/1.1") print $(i+1);}'

Using this command i can able to get the HTTP error code.
using this code + with the help of conditonal statements i can able to write the script. but this is the right way to monitor the website using script, or any option is available??
Again, you don't say WHAT you're trying to monitor, HOW. And there is no 'right way'...the right way is whatever way you need, to do what you want. Bash scripting is only ONE method...there are many programs in Perl, Python, Ruby, and probably a dozen other languages that can do this. YOU have to decide what is best, and make it fit your needs.
Quote:
@TB0ne : thanks for your link. with the help of that link i get some ideas :-)
Lots more links, but you need to try to look them up yourself. Again, read some scripting tutorials, and the man pages on the commands.
 
1 members found this post helpful.
Old 03-08-2011, 09:34 PM   #9
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
There are many ways to monitor a web server. You need to find the method that works for your situation. What aspect of the server are you concerned about? Page content? Response time? You could write the script yourself or utilize one of the many projects that have already attempted to solve this problem.
 
Old 03-09-2011, 02:10 AM   #10
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi TB0ne,

My requirement is we need to monitor the url, which are hosted from my server, whether the URL is working fine or down like that.

Because in my company we face one issue one time even the HTTP service is running but i got 502 error, because of java heap size prob.

Now i need to write script to identify, to check url is working fine or not, and response time, and all.

@stickman. below i mention my requirement , i have some basic ideas only in bash scripting so with the help of examples,man page only i can able to understand, and iam trying also.


Thanks in Advance.
Anish Kumar.V
 
Old 03-09-2011, 02:16 AM   #11
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

@anishkumarv: Did you look at the link posted by TB0ne in post #6? That's a 'ready made solution', what more can you need?

Kind regards,

Eric
 
Old 03-09-2011, 01:21 PM   #12
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi EricTRA,

some things i cant able to understand in this script.

curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://linuxquestions.org
| grep -i -m 1 “time_takentime” | cut -d”:” -f2

if i entered this command means it shows.

cut: the delimiter must be a single character

When I read man for cut it states ... delim can be a multi-byte character. ... What am I doing/interpreting wrong here?

Thanks in Advance!!
Anish Kumar.V
 
Old 03-09-2011, 04:42 PM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,948

Rep: Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693Reputation: 3693
Quote:
Originally Posted by anishkumarv View Post
Hi EricTRA,
some things i cant able to understand in this script.

curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://linuxquestions.org
| grep -i -m 1 “time_takentime” | cut -d”:” -f2

if i entered this command means it shows.
cut: the delimiter must be a single character

When I read man for cut it states ... delim can be a multi-byte character. ... What am I doing/interpreting wrong here?
Running the command as you entered, doesn't give the string "time_takentime", anywhere in the output. Change it to "totaltime" (without the double quotes), and it will work. Try stepping through commands like this one at a time, to see what you're getting. And again, you need to look at some bash scripting tutorials...
 
Old 03-10-2011, 01:49 AM   #14
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295Reputation: 1295
Hello,

TB0ne nailed what you need to do if you're in doubt, take it one command at a time if you don't understand what it does. Following TB0ne's guidance, did you get it to work and are the results as expected?

Kind regards,

Eric
 
Old 03-10-2011, 02:30 AM   #15
sandy.bhadoriya
Member
 
Registered: Dec 2010
Posts: 31

Rep: Reputation: 3
#!/bin/bash
# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# -------------------------------------------------------------------------
# Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# RHEL / CentOS / Fedora Linux restart command
RESTART="/sbin/service httpd restart"

# uncomment if you are using Debian / Ubuntu Linux
#RESTART="/etc/init.d/apache2 restart"

#path to pgrep command
PGREP="/usr/bin/pgrep"

# Httpd daemon name,
# Under RHEL/CentOS/Fedora it is httpd
# Under Debian 4.x it is apache2
HTTPD="httpd"

# find httpd pid
$PGREP ${HTTPD}

if [ $? -ne 0 ] # if apache not running
then
# restart apache
$RESTART
fi



you can use this script if you want.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a Bash / Perl script to read the New RSS feeds (XML url) frenchn00b Programming 1 02-13-2011 09:06 AM
perl script to parse url from xml URL Freaksta Linux - General 1 01-20-2011 08:46 PM
log monitor bash script tronica Programming 5 05-14-2008 03:53 AM
Using PHP, run bash script and see results on Server's Monitor xmrkite Linux - Software 6 10-17-2006 02:28 PM
Bash script help for dummy. need to monitor and restore my adsl connection default Programming 10 07-09-2004 05:10 PM


All times are GMT -5. The time now is 10:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration