- Home
- Contact
-
Articles / Code
- HTML/CSS (2)
-
Scripts (17)
- Twitter & bash
- Generate sitemaps
- random floating point in bash
- Gmail script
- Python http POST requests
- Bashrc enhancements
- commandline <> nautilus
- Word Definitions
- Synonyms
- mysqld monitor
- remote server
- links and emailaddresses
- Apache Analyser
- remote ipaddress
- OOP Python
- mysql tuning
- diskspace notification
- Server Configuration (6)
- ICT-security (2)
Generate sitemaps
» Articles / Code » Scripts » Generate sitemaps
A nice script I made for generating (google) sitemaps n Bash.
it simply mirrors and extracts the url's and creates a xml file.Then it notifies google that a new sitemap is created.
#!/bin/bash
url="yoursite.com"
date=`date +'%FT%k:%M:%S+00:00'`
freq="weekly"
prio="0.5"
rm sitemap.xml
list=`wget -r --delete-after $url --reject=.rss.gif,.png,.jpg,.css,.js,.txt,.ico 2>&1 |grep "\-\-" |grep http | awk '{ print $3 }'`
array=($list)
echo ${#array[@]} "pages detected for $url"
echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' >> sitemap.xml;
for ((i=0;i<${#array[*]};i++)); do
echo "<url>
<loc>${array[$i]:0}</loc>
<priority>$prio</priority>
<lastmod>$date</lastmod>
<changefreq>$freq</changefreq>
</url>" >> sitemap.xml
done
echo "</urlset>" >> sitemap.xml
#notify google
wget -q --delete-after http://www.google.com/webmasters/tools/ping?sitemap=http://$url/sitemap.xml
rm -r ${url}
exit 0