#!/bin/bash
mysql olegon -B -N -e "select pagetext from post where pagetext like '%http%'">f_links.tmp
cat f_links.tmp | tr "[]" "<>" | sed -e 's/<\/img>/<\/img>\n/gi' | sed -n -e 's/.*<img>\(.*\)<\/img>.*/\1/pi' >flinks2.tmp
cat f_links.tmp | tr "[]" "<>" | sed -e 's/<\/url>/<\/url>\n/gi' | sed -n -e 's/.*<url>\(.*\)<\/url>.*/\1/pi' >>flinks2.tmp
uniq -i flinks2.tmp flinks.tmp
rm f_links.tmp
rm flinks2.tmp
cat flinks.tmp | while read URL
do
STATUS_CODE=`curl --output /dev/null --silent --head --write-out '%{http_code}\n' $URL`
if [ $STATUS_CODE -eq 0 ] || [ $STATUS_CODE -eq 404 ] ; then
echo "$STATUS_CODE $URL"
mysql olegon -e "update post set pagetext=replace(pagetext,'$URL','') where pagetext like '%$URL%'"
fi
done
rm flinks.tmp
mysql olegon <<EOF
update post set pagetext=replace(pagetext,'','');
update post set pagetext=replace(pagetext,'','');
update post set pagetext=replace(pagetext,'','');
update post set pagetext=replace(pagetext,'','');
update post set pagetext=replace(pagetext,'','');
update post set pagetext=replace(pagetext,'','');
delete from post where trim(pagetext)='' and postid not in (select firstpostid from thread);
EOF