Bash Script to Find the status of URL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash Script to Find the status of URL
# 1  
Old 03-13-2011
Bash Script to Find the status of URL

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" ;;
301) echo "$timevar $i $statuscode bad" ;;
esac
done

this is the simple script which i wrote to find the status of URL 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:
13-03-2011_16.05.05 google.com 301 bad
13-03-2011_16.05.05 stayzone.in 200 okay
13-03-2011_16.05.05 grpa.r-lite.com 200 okay
and this has to be store in a file (like log) and critical 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

---------- Post updated at 09:19 PM ---------- Previous update was at 04:06 PM ----------

no reply :-( :-( is it tough to understand !!!!
# 2  
Old 03-13-2011
Should be as simple as this:

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

# 3  
Old 03-14-2011
hi chubler,

Thanks for your help dude.!!! It works great!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to find Memory status in AIX

Hi All, There is a shell script that captures Memory status in AIX 6.1 64 bits! I need it to be validated by shell script experts for the following: Shell Script: cat memusageAIX.sh #!/usr/bin/ksh # # Memory usage under AIX # USED=`svmon -G | head -2 | tail -1 | awk '{ print $3... (1 Reply)
Discussion started by: a1_win
1 Replies

2. Shell Programming and Scripting

How to find invalid URL in a text file using shell script?

How to find and remove invalid URLs in a text file using shell script? (1 Reply)
Discussion started by: vel4ever
1 Replies

3. Shell Programming and Scripting

Help needed with bash script providing battery status

I'm really new to even doing a bash "hello world" script, so maybe someone would know how to do the following task, using bash scripting Need to login using ssh from one dell server into another dell server, and obtain the raid battery status, using dell's open manage software commands; then... (5 Replies)
Discussion started by: AJ-102111
5 Replies

4. Programming

Bash Script to Find the status of URL

#!/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... (0 Replies)
Discussion started by: anishkumarv
0 Replies

5. Shell Programming and Scripting

bash curl escape & in url

I'm running a curl command in bash, but the & in the middle causes the second half of the line to run in the background, here's what I'm trying to do: lat="37.451" lon="-122.18" url="http://ws.geonames.org/findNearestAddress?lat=$lat&lng=$lon" curl -s "$url" I tried escaping the & with \&,... (4 Replies)
Discussion started by: unclecameron
4 Replies

6. Shell Programming and Scripting

bash about url existence

Hi, I want to make a bash script which is running like : 1.sh http://www. google.com and check if the url does exist printing a message. I want to save the source code of this page in a file. Could you help me ? (4 Replies)
Discussion started by: peter20
4 Replies

7. Shell Programming and Scripting

Bash script (using find and grep)

I'm trying to make a simple search script but cannot get it right. The script should search for keywords inside files. Then return the file paths in a variable. (Each file path separated with \n). #!/bin/bash SEARCHQUERY="searchword1 searchword2 searchword3"; for WORD in $SEARCHQUERY do ... (6 Replies)
Discussion started by: limmer
6 Replies

8. Shell Programming and Scripting

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

9. UNIX for Advanced & Expert Users

url calling and parameter passing to url in script

Hi all, I need to write a unix script in which need to call a url. Then need to pass parameters to that url. please help. Regards, gander_ss (1 Reply)
Discussion started by: gander_ss
1 Replies

10. Shell Programming and Scripting

find subdomain in url

I want to find out subdomains in the url using shell script. e.g narendra.eukhost.com abc.domainname.co.uk I want to extract narendra & abc from the above urls. Please any one can suggest idea or script ? (2 Replies)
Discussion started by: nrbhole
2 Replies
Login or Register to Ask a Question