LinuxQuestions.org
Visit Jeremy's Blog.
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-10-2011, 01:35 AM   #16
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

Quote:
Originally Posted by sandy.bhadoriya View Post
you can use this script if you want.
Hello,

The OP is looking for a script to monitor URL, not for one that monitors a local service. And if you don't mind, when you post code please use code tags for readability. Thank you.

Kind regards,

Eric
 
Old 03-10-2011, 12:56 PM   #17
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi Tb0ne


as per your advice

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

the output is displayed like that.

cut: the delimiter must be a single character
Try `cut --help' for more information.

Then i made changes..in command.

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

and the display is like that..

0.000n”“totaltime

As per my understand the command which is used for to get that taketime right?

When we execute this command.

curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://stayzone.in


“totaltime:0.000n”“totaltime:0.000n”HTTP/1.1 200 OK
Date: Thu, 10 Mar 2011 18:45:43 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Wed, 19 Jan 2011 12:14:14 GMT
ETag: "1a680b2-a39-f4901180"
Accept-Ranges: bytes
Content-Length: 2617
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=UTF-8

“totaltime:0.580n”

and it display like this..

i hope the entire command which is used for to display the bold value(totaltime) alone right??

but still i didn't get iam trying for that..you guys please give your valuable suggestions..

i am beginner to scripting so that only this much struggling and time to understand each command..


With Regards
Anish Kumar.V
 
Old 03-10-2011, 01:28 PM   #18
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,886

Rep: Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258
Quote:
Originally Posted by anishkumarv View Post
Hi Tb0ne
as per your advice

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

the output is displayed like that. cut: the delimiter must be a single character Try `cut --help' for more information.

Then i made changes..in command.
curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://stayzone.in | grep -i -m 1 totaltime | cut -d: -f2

and the display is like that..
0.000n”“totaltime

As per my understand the command which is used for to get that taketime right?
No. Once again, you need to read the man pages for the different commands you're entering. Step through them one at a time, and see what they're giving you. The "-m 1" will get the FIRST occurance...again, read the man page. If you look at the output of the curl command, it's giving MORE THAN ONE. Adjust the command accordingly, to get the one that returns the time.
Quote:
When we execute this command.
curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://stayzone.in

“totaltime:0.000n”“totaltime:0.000n”HTTP/1.1 200 OK
Date: Thu, 10 Mar 2011 18:45:43 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Wed, 19 Jan 2011 12:14:14 GMT
ETag: "1a680b2-a39-f4901180"
Accept-Ranges: bytes
Content-Length: 2617
Vary: Accept-Encoding
Connection: close
Content-Type: text/html; charset=UTF-8

“totaltime:0.580n” and it display like this..i hope the entire command which is used for to display the bold value(totaltime) alone right?? but still i didn't get iam trying for that..you guys please give your valuable suggestions..

i am beginner to scripting so that only this much struggling and time to understand each command..
We have given you suggestions and the entire solution. YOU need to read the documentation, again AGAIN, read some scripting tutorials, and make it work the way you want to. Think about each command, and read the documentation for each command. Work through the problem. You will ALWAYS be a beginner in anything, if you don't try to learn and/or apply what you've learned.
 
1 members found this post helpful.
Old 03-10-2011, 08:51 PM   #19
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi TB0ne,

ya i accept all your guidelines, but still some understanding issue in this script.

Quote:
#!/bin/bash
timevar=`date +%F_”%H_%M”` #—– > Storing Date and Time in a Variable.
get_contents=`cat urls.txt` #—- > Getting content of website from file. Note the file should not contain any http:// as its already been taken care of.
######### Next Section Does all the processing #########
echo “***URL*** ***StatusCode*** ***Status*** ***Check Time*** ***Response Time*** ***Uptime*** ***Downtime***” > logfile_$timevar.txt

for i in $get_contents
do
statuscode=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “HTTP” | awk ‘{print $2}’`

if [ "$statuscode" == "200" ]; then
time_taken=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “time_takentime” | cut -d”:” -f2`

output=`echo “$i” “$statuscode” “Accessed” “$timevar” “$time_taken” “5″ “0″`
echo $output >> logfile_$timevar.txt
else
if [ "$statuscode" == "301" ]; then
time_taken=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “time_takentime” | cut -d”:” -f2`
output=`echo “$i” “$statuscode” “Accessed But Moved Away” “$timevar” “$time_taken” “5″ “0″`
echo $output >> logfile_$timevar.txt
else
if [ "$statuscode" == "302" ]; then
time_taken=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “time_takentime” | cut -d”:” -f2`
output=`echo “$i” “$statuscode” “Accessed But Temporarily Moved Away” “$timevar” “$time_taken” “5″ “0″`
echo $output >> logfile_$timevar.txt
else
if [ "$statuscode" == "500" ]; then
time_taken=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “time_takentime” | cut -d”:” -f2`
output=`echo “$i” “$statuscode” “Internal Server Error” “$time_taken” “0″ “5″`
echo $output >> logfile_$timevar.txt
else
if [ "$statuscode" == "404" ]; then
time_taken=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “time_takentime” | cut -d”:” -f2`
output=`echo “$i” “$statuscode” “Not Found” “$timevar” “$time_taken” “0″ “5″`
echo $output >> logfile_$timevar.txt
else
if [ "$statuscode" == "403" ]; then
time_taken=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “time_takentime” | cut -d”:” -f2`
output=`echo “$i” “$statuscode” “Forbidden” “$timevar” “$time_taken” “0″ “5″`
echo $output >> logfile_$timevar.txt
else
time_taken=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “time_takentime” | cut -d”:” -f2`
curl -S –connect-timeout 30 -s -I -L http://$i > error.txt 2>&1
error_file=`cat error.txt | cut -d”)” -f2 | cut -d” ” -f2-100`
error_result=`echo $error_file | sed ‘s/’\”//g’`
output=`echo “$i” “NA” “$error_file” “$timevar” “$time_taken” “0″ “5″`
echo $output >> logfile_$timevar.txt
echo $error_file | mail -s “Error Received From Monitoring $timevar” yourself@yourdomainname.com — -f someone@yourdomainname.com
fi
fi
fi
fi
fi
fi
done
This was the original script posted in that blog.

to find staus code :
they given code like that.
Quote:
statuscode=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “HTTP” | awk ‘{print $2}’`
but i didnt get the exact output what i expect.

so instead of that code i used this code to find status code.

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


then we need to find taketime for that they given code like that

Quote:
time_taken=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | grep -i -m 1 “time_takentime” | cut -d”:” -f2`
in beginning i am quite confuse in this code but now okay and iam trying to get the exact output what i expect

we need this time only right the URL resolving time.

“totaltime:0.591n”

for that if i execut this command

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

it shows output like this.

0.000n”“totaltime
0.580n”

for this iam working now how to get the resolving time alone from the output.

and then still i have doubt in the next few lines also...

Quote:
output=`echo “$i” “$statuscode” “Internal Server Error” “$time_taken” “0″ “5″`

for what purpose we are using “0″ “5″ this value here

and this commands also...
Quote:
curl -S –connect-timeout 30 -s -I -L http://$i > error.txt 2>&1
error_file=`cat error.txt | cut -d”)” -f2 | cut -d” ” -f2-100`
error_result=`echo $error_file | sed ‘s/’\”//g’`

Thanks for your patience to answer me again and again regarding this script, from this i understood one thing even we can easily write the own script compare to understanding others script :-) , again and again why iam willing to use this script means for me less time only to complete the project and this script is 100% fulfilled my requirements. but now temporarily iam running the script in server, using the status code alone with the help of conditional statements, but there is some drawbacks in that to overcome that issues i need a script like this and i am working on that...


Thanks and Regards
Anish Kumar.V
 
Old 03-11-2011, 10:31 PM   #20
stickman
Senior Member
 
Registered: Sep 2002
Location: Nashville, TN
Posts: 1,552

Rep: Reputation: 53
It's probably overkill, but you might want to consider looking into something like Nagios. Even if you don't run a full Nagios setup, you might be able to use the check_http plugin in a script to get the functionality that you need. You mentioned problems with java heap size so you might also want to do some app profiling.
 
Old 03-12-2011, 08:04 AM   #21
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi stickman,

Ya i know about nagios and how to configure it and all..but nagios not full fill my requirement so only now i move to this script for temporarily i need to finish this script within this wk so only i am posting my requirement in different different threads. i hope I'll finish the script with documentation.


Thanks and Regards
Anish Kumar.V
 
Old 03-12-2011, 01:24 PM   #22
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Code:
#!/bin/bash
timevar=`date +%F_”%H_%M”` #—– > Storing Date and Time in a Variable
get_contents=`cat urls.txt`  #—- > Getting content of website from file. Note the file should not contain any http:// as its already been taken care of
######### Next Section Does all the processing #########
for i in $get_contents
do
statuscode=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | awk '{for(i = 1; i<=NF; i++) if($i=="“totaltime:0.000n”“totaltime:0.000n”HTTP/1.1") print $(i+1);}'`
case $statuscode in
200) echo "$timevar $i $statuscode okay" ;;
301) echo "$timevar $i $statuscode bad" ;;
esac
done

this is the simple script which i adopted from TBOne link now i have doubt how i generate the log file, inside how can i give the option to store the output as file ,

now the output like this ,
Quote:
2011-03-13_”00_50” google.com 200 okay
and this has to be store in a file (like log) and criticale error code displayed means it automatically send mail to admin. with the error code.

is it possible to generate a script like that.


With Regards
Anish Kumar.V

Last edited by anishkumarv; 03-12-2011 at 01:37 PM. Reason: need to change the code
 
Old 03-13-2011, 10:53 AM   #23
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
please close this thread!!! Thanks for all to reply me!!! to this thread no one respond means what use if still opened means...
 
Old 03-13-2011, 11:47 AM   #24
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,886

Rep: Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258
Quote:
Originally Posted by anishkumarv View Post
please close this thread!!! Thanks for all to reply me!!! to this thread no one respond means what use if still opened means...
No idea what this sentence means...it makes no sense.

And again, you need to read some scripting tutorials, because it's clear by your questions you have not, despite suggestions to do so. If you want the output of your script to go to a file, then use "> /path/to/filename.log", and your output will be written there.

Again, read and learn. Look at the tutorials, that's what they're there for.
 
Old 03-13-2011, 12:01 PM   #25
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Hi TB0ne,

exec 1>logfile 2>&1

inside the script i used this code!! it works

but still some holes are there in my script if the critical error came means automatically send mails to admin, and sometimes if the URL display blank page means how its generate code.
like this, some holes...

Thank u TB0ne for all the times you are respond my question's very patience..thanks alot..

With Regards
Anish Kumar.V
 
Old 03-13-2011, 12:04 PM   #26
Brocifer
Member
 
Registered: Mar 2011
Posts: 46

Rep: Reputation: 1
Quote:
Originally Posted by TB0ne View Post
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...
Don't encapsulate your delimiter in cut. i.e. it is literally telling you the problem. -d expects a single character, that of your delimiter without quotes.

Blech, quoted wrong post. Ah well, looks like he finally found a solution.

Last edited by Brocifer; 03-13-2011 at 12:05 PM.
 
Old 03-14-2011, 01:41 PM   #27
anishkumarv
Member
 
Registered: Feb 2010
Location: chennai - India
Distribution: centos
Posts: 289

Original Poster
Rep: Reputation: 10
Code:
#!/bin/bash
timevar=`date +%d-%m-%Y_%H.%M.%S` #—– > Storing Date and Time in a Variable
get_contents=`cat urls.txt`  #—- > Getting content of website from file. Note the file should not contain any http:// as its already been taken care of
echo "Datae-time          URL    Status code  Report" > aaa.txt
######### Next Section Does all the processing #########
for i in $get_contents
do
statuscode=`curl –connect-timeout 30 -w “totaltime:%{time_total}\n” -s -I -L http://$i | awk '{for(i = 1; i<=NF; i++) if($i=="“totaltime:0.000n”“totaltime:0.000n”HTTP/1.1") print $(i+1);}'`
case $statuscode in
200) 
    echo "$timevar $i $statuscode okay" >> /path/to/my/logfile.txt;;
301) 
    echo "$timevar $i $statuscode bad" >> /path/to/my/logfile.txt
    echo "Status $statuscode found" | mail -s "Check of $i failed" notify@your.email.addr
;;
esac
done
Hi Thanks to all to reply my queries!!! spl thanks to TBOne...Finally i wrote this simple script
Quote:
TO FIND THE STATUS OF THE URL
as per my understandin...:-) :-) thanks to all!!!
 
  


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 08:06 AM
perl script to parse url from xml URL Freaksta Linux - General 1 01-20-2011 07:46 PM
log monitor bash script tronica Programming 5 05-14-2008 02:53 AM
Using PHP, run bash script and see results on Server's Monitor xmrkite Linux - Software 6 10-17-2006 01:28 PM
Bash script help for dummy. need to monitor and restore my adsl connection default Programming 10 07-09-2004 04:10 PM


All times are GMT -5. The time now is 09:51 PM.

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