# Simple Bash Shell Scripts:



## regexorcist (Feb 18, 2010)

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  )  


```
#!/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 (Mar 7, 2010)

*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*).


```
#!/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).


----------



## [I.R.A]_FBi (Mar 7, 2010)

me like


----------

