Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- ## Geoip database syncer
- f=/var/mkctl/geo_files.zip
- d=/var/mkctl/geo_files
- wget -O $f http://ipgeobase.ru/files/db/Main/geo_files.zip &&
- (test -d $d || mkdir $d) &&
- rm -rf $d/* $d/.[a-zA-Z0-9] > /dev/null 2>&1 &&
- unzip $f -d $d &&
- echo "cities" &&
- echo "DROP TABLE IF EXISTS geoip_location_new;CREATE TABLE geoip_location_new LIKE geoip_location;SET NAMES cp1251;" > /tmp/q &&
- cat $d/cities.txt | sed -e "s/\"/'/g" | awk -F ' ' 'BEGIN {OFS = FS} {print "INSERT INTO geoip_location_new (id, city, subject, district, latitude, longitude) VALUES (\""$1"\", \""$2"\", \""$3"\", \""$4"\", \""$5"\", \""$6"\");";}' >> /tmp/q &&
- echo "DROP TABLE IF EXISTS geoip_location_old; RENAME TABLE geoip_location TO geoip_location_old; RENAME TABLE geoip_location_new TO geoip_location;" >> /tmp/q &&
- cat /tmp/q | mysql -u scriptwr --password=kSOo7PbCqsnWMn9c9w3TBxIP articles &&
- echo "cidr" &&
- echo "DROP TABLE IF EXISTS geoip_blocks_new;CREATE TABLE geoip_blocks_new LIKE geoip_blocks;SET NAMES cp1251;" > /tmp/q &&
- cat $d/cidr_optim.txt | sed -e "s/\"/'/g" | awk -F ' ' 'BEGIN {OFS = FS} {print "INSERT INTO geoip_blocks_new (startIpNum, endIpNum, IpTextBlock, CountryCode, CityCode) VALUES (\""$1"\", \""$2"\", \""$3"\", \""$4"\", \""$5"\");";}' >> /tmp/q &&
- echo "DROP TABLE IF EXISTS geoip_blocks_old; RENAME TABLE geoip_blocks TO geoip_blocks_old; RENAME TABLE geoip_blocks_new TO geoip_blocks;" >> /tmp/q &&
- cat /tmp/q | mysql -u scriptwr --password=kSOo7PbCqsnWMn9c9w3TBxIP articles &&
- rm /tmp/q
- ~
Advertisement
Add Comment
Please, Sign In to add comment