techPowerUp! Forums

Go Back   techPowerUp! Forums > Software > Programming & Webmastering

Reply
 
Thread Tools
Old Feb 18, 2010, 12:59 AM   #1
regexorcist
75 Posts
 
regexorcist's Avatar
 
Join Date: Feb 2010
Location: ~/
Posts: 157 (0.13/day)
Thanks: 66
Thanked 46 Times in 38 Posts

System Specs

Simple Bash Shell Scripts:

This thread is for simple bash shell scripts or code snippets.

Here is a simple script I put together using wget, grep, sed
and of course a few regular expressions (regex... see my username )

Code:
#!/bin/bash

var_links=`wget -q -L -O - \
 http://www.phillylinux.org/ \
 | grep -o '<a href="http://[^"]*' \
 | sed -e 's/<a href=\"//' -e 's/\"/\n/'`

wget --spider $var_links
As you can see, I use wget to retrieve the webpage
and after parsing, I use wget again to spider each link
and display the status.

Here is the page that is retrieved (it has about 30 links or so).




Here I start the script and the data starts streaming.




Here we have scrolled down to the end where the script has finished,
it took about 20 seconds or so to complete.



The script may be small and simple, but for large website maintenance
it's very powerful. My regular expressions are set up for absolute links
but easily modified for relative ones, just as the spider output could be
grepped down to a single line.

Have Fun and lets see some of your scripts
__________________
regexorcist is offline  
Reply With Quote
Old Mar 7, 2010, 12:27 AM   #2
regexorcist
75 Posts
 
regexorcist's Avatar
 
Join Date: Feb 2010
Location: ~/
Posts: 157 (0.13/day)
Thanks: 66
Thanked 46 Times in 38 Posts

System Specs

Weather by zipcode:

I wrote this little script a while back
and there were a few that found it useful.

I use the google weather API and parse the
result with a few regular expressions (regex).

Code:
#!/bin/bash

echo -n "Enter a valid 5-digit zipcode: "
read zipcode

var_url="http://www.google.com/ig/api?weather=$zipcode&hl=en"

var_weather_wget=`wget -q $var_url -O -`
var_weather_xml=`echo "$var_weather_wget" | sed 's/<forecast_conditions>.*//'`
var_weather=`echo "$var_weather_xml" | sed 's/></>\n</g'`

var_date=`echo "$var_weather" | grep -e '<forecast_date' | \
sed -e 's/<forecast_date data="//' -e 's/"\/>//'`

var_city=`echo "$var_weather" | grep -e '<city' | \
sed -e 's/<city data="//' -e 's/"\/>//'`

var_condition=`echo "$var_weather" | grep -e '<condition' | \
sed -e 's/<condition data="//' -e 's/"\/>//'`

var_temp_f=`echo "$var_weather" | grep -e '<temp_f' | \
sed -e 's/<temp_f data="//' -e 's/"\/>//'`

var_temp_c=`echo "$var_weather" | grep -e '<temp_c' | \
sed -e 's/<temp_c data="//' -e 's/"\/>//'`

var_humidity=`echo "$var_weather" | grep -e '<humidity' | \
sed -e 's/<humidity data="//' -e 's/"\/>//'`

var_wind=`echo "$var_weather" | grep -e '<wind' | \
sed -e 's/<wind_condition data="//' -e 's/"\/>//'`

echo "Date: $var_date"
echo "City: $var_city"
echo "Condition: $var_condition"
echo "Temp: $var_temp_f Deg. Fahrenheit / $var_temp_c Deg. Celsius"
echo "$var_humidity"
echo "$var_wind"
Here it is in action...



As you can see, I've typed a zipcode and hit <enter>
see the result...



The same API could be used w/ php or any other language
on a website. (I've also used it w/ python).
__________________
regexorcist is offline  
Reply With Quote
Old Mar 7, 2010, 02:35 AM   #3
[I.R.A]_FBi
Eligible for custom title
 
[I.R.A]_FBi's Avatar
 
Join Date: May 2007
Location: c:\programs\kitteh.exe
Posts: 6,152 (2.80/day)
Thanks: 724
Thanked 556 Times in 461 Posts

System Specs

me like
__________________
Rig 1+1
Athlon XP 2200+, MSI KM2M Combo, ATI 9200SE 128 MB DDR, 2 X 512 MB DDR333, 250GB + 80 HDD?

“try intel cpu, amd is only good for going to nude sites” -firehawkxd
“go for the 5850 now and play games while the nvidiots wait for the ceo to show an actual working product” -W1zzard
“An MSI logo? This offends my retina. I await your apology.” -MRCL

www.autolounge.com.jm
[I.R.A]_FBi is offline  
Reply With Quote
The Following User Says Thank You to [I.R.A]_FBi For This Useful Post:
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Tcl/Tk scripts: regexorcist Programming & Webmastering 4 Feb 18, 2010 02:28 AM
Simple perl scripts: regexorcist Programming & Webmastering 0 Feb 16, 2010 09:26 PM
Simple Python Scripts regexorcist Programming & Webmastering 10 Feb 12, 2010 05:10 PM
simple ? for a simple mind freeboy Motherboards & Memory 3 Feb 21, 2007 08:33 PM
scince you guy like to bash intel tony929292 General Hardware 8 Nov 27, 2005 11:10 PM


All times are GMT. The time now is 10:07 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
no new posts