6月份放置jamesqi.com这个站点的服务器出了一些问题,一直没有搞好,站点临时转移到其它服务器上,所以也没有写什么日志,现在依然没有搞好,但还是先写日志吧。
我们有些系列网站数量多,再加上多语言后,xmlsitemap网站地图的数量就更多了,例如50子网站*50种语言后就是2500个网站地图,生成就需要很长时间,中途还可能遇到各种报错,而生成后人工检查也难以进行,7月1日编写了一个简单的脚本来进行自动检查、记录:
checksitemap.sh
#!/bin/bash DB=(zip ak al ar az ca co ct dc de fl ga hi ia id il in ks ky la ma md me mi mn mo ms mt nc nd ne nh nj nm nv ny oh ok or pa ri sc sd tn tx ut va vt wa wi wv wy) #DB=(zip al ar az ca co ct dc de fl ga hi ia id il in ks ky la ma md me mi mn mo ms mt nc nd ne nh nj nm nv ny oh ok or pa ri sc sd tn tx ut va vt wa wi wv wy) #DB=(ak al) LA=(af sq ar hy az bg ca zh-hans zh-hant hr cs da nl eo et fi fr gl ka de el hu is ga it ja ko lv lt mk ms mt fa pl pt-pt ro ru sr sk sl es sw sv th tr uk vi cy) #LA=(af) for i in "${DB[@]}";do echo ----------------- database: $i.postcodebase.com ----------------- d="http://$i.postcodebase.com" echo language: en wget --spider --append-output=checksitemap.log http://$i.postcodebase.com/sitemap.xml for j in "${LA[@]}";do echo language: $j wget --spider --append-output=checksitemap.log http://$i.postcodebase.com/$j/sitemap.xml done done
用命令行运行:
sh checksitemap.sh > checksitemap.log
这样运行记录都放在checksitemap.log中,事后查看。
其实还可以编写得更仔细一些,把状态标记得更简单,或者改用php程序来写,以后可以来进行。
用Shell脚本毕竟没有PHP方便灵活,现在又添加了PHP程序版本,可以更方便实现各种url的检查,输出结果也更加清晰:
<?php /* * check url * jamesqi 2013-9-13 */ $array_site=array('zip','ak','al','ar','az','ca','co','ct','dc','de','fl','ga','hi','ia','id','il','in','ks','ky','la','ma','md','me','mi','mn','mo','ms','mt','nc','nd','ne','nh','nj','nm','nv','ny','oh','ok','or','pa','ri','sc','sd','tn','tx','ut','va','vt','wa','wi','wv','wy'); #$array_lang=array('af','sq','ar','hy','az','bg','ca','zh-hans','zh-hant','hr','cs','da','nl','eo','et','fi','fr','gl','ka','de','el','hu','is','ga','it','ja','ko','lv','lt','mk','ms','mt','fa','pl','pt-pt','ro','ru','sr','sk','sl','es','sw','sv','th','tr','uk','vi','cy'); //drupal 6, 48 languages #$array_lang=array('af','sq','ar','hy','az','bg','ca','zh-hans','zh-hant','hr','cs','da','nl','eo','et','fi','fil','fr','gl','ka','de','el','hu','is','ga','it','ja','ko','lv','lt','mk','ms','mt','fa','pl','pt','ro','ru','sr','sk','sl','es','sw','sv','th','tr','uk','vi','cy'); //drupal 7, 49 languages $array_lang=array('af','xx','admin'); //test foreach ($array_site as $site) { $url="http://$site.postcodebase.com"; print "url=$url\n"; print "language: en - "; $fp=@fopen($url,'r'); if ($fp==FALSE) { print "error\n"; } else { print "ok\n"; } foreach ($array_lang as $lang) { print "language: $lang - "; $url_lang="$url/$lang"; $fp=@fopen($url_lang,'r'); if ($fp==FALSE) { print "error\n"; } else { print "ok\n"; } } } ?>
评论