TIME NOW
World current time now,
CALENDAR
Calendar monthly, yearly
login CONVERT LENGTH
login CONVERT TEMPERATURE
login DICTIONARIES, LISTS
login SCIENCE EDUCATION RELIGION
login WORK CALCULATOR
login CALCULATE LIFE

Linux commands, scripts, examples, tutorial

Previous articlePage bottomNext article  ALL TOPICS

Linux. wget. Download files, write text to mysql database script

 wget bash script to download text files and insert into database:
 
#!/bin/bash

 folder='/var_www/programva_com/_common_/_countries/ip'

 file1='delegated-ripencc-latest'
 file2='delegated-apnic-latest'
 file3='delegated-arin-latest'
 file4='delegated-afrinic-latest'
 file5='delegated-lacnic-latest'

 file='t_geo_ip.full.txt'
 fileFin='t_geo_ip.txt'

    rm -f $folder/delegate*

    wget -t 3 -o /dev/null -P $folder ftp://ftp.ripe.net/pub/stats/ripencc/$file1 ;  sleep 10
    
    wget -t 3 -o /dev/null -P $folder ftp://ftp.apnic.net/pub/stats/apnic/$file2 ;  sleep 10

    wget -t 3 -o /dev/null -P $folder ftp://ftp.arin.net/pub/stats/arin/$file3 ;  sleep 10

    wget -t 3 -o /dev/null -P $folder ftp://ftp.afrinic.net/pub/stats/afrinic/$file4 ;  sleep 10

    wget -t 3 -o /dev/null -P $folder ftp://ftp.lacnic.net/pub/stats/lacnic/$file5 ;  sleep 10
    
    
if [ -f $folder/$file1 -a -f $folder/$file2 -a -f $folder/$file3 -a -f $folder/$file4 -a -f $folder/$file5 ]

then

    echo "ok"

else

    echo "IP not" | mail -s "ip not" a[at]a.lt

    echo "exit"

    exit 0

fi


    
# echo wget
    
    cat $folder/delegated* > $folder/$file ;  sleep 5

# echo mv

grep LT $folder/$file | grep ipv4 | awk 'BEGIN { FS = "|" } ;  { print $2 , $4 , $7  } ' > $folder/$file.lt

grep ipv4 $folder/$file | awk 'BEGIN { FS = "|" } ;  { print $2 , $4 , $5, $7 } '> /tmp/$fileFin
#echo 5


/usr/local/mysql/bin/mysqlimport --debug  --delete --columns=name,ip,range,type --default-character-set=utf8 -uroot -proot --fields-terminated-by=' ' db_1 /tmp/$fileFin

rm /tmp/$fileFin

mail  -s "for test purposes  - IP" a[at]a.lt < $folder/$file.lt

exit 0
 
Previous articlePage topNext article  ALL TOPICS


Guest:
Hi
/usr/local/mysql/bin/mysqlimport  is rarely used utility.

2013-06-12 05:49:01

 Use username: Guest, Anonymous, Programmer






QUOTES:
Do not learn more than you absolutely need to get through life.
Karl Kraus
If you can smile when things go wrong, you have someone in mind to blame.
Anonymous
Lactomangulation, n.: Manhandling the "open here" spout on a milk carton so badly that one has to resort to using the "illegal" side.
Rich Hall, "Sniglets