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"; } } } ?>
评论