]>
Commit | Line | Data |
---|---|---|
2efe7c9e EK |
1 | #!/bin/bash - |
2 | ||
3 | # | |
4 | # Cronjob script to update GeoIP for pmacct daily | |
5 | # | |
6 | # $author: ummeegge ipfire org ; $date: 21.10.2019 | |
7 | ######################################################## | |
8 | # | |
9 | ||
10 | # Locations | |
11 | WORKDIR="/tmp/geoip"; | |
12 | GEOIPDIR="/usr/share/pmacct/geoip"; | |
13 | URLS=" | |
14 | http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz | |
15 | "; | |
16 | ||
17 | # Check if Pmacct is running, else exit here | |
18 | if ! pgrep 'pmacct'; then | |
19 | logger -t pmacct "Pmacct is nor running. GeoIP updater script in /etc/fcron.daily/ is useless." | |
20 | exit 1 | |
21 | fi | |
22 | # Create temporary work dir and switch to it | |
23 | /bin/mkdir -p ${WORKDIR} && cd ${WORKDIR}; | |
24 | # Download GeoIP with download log. If download fails write it to messages | |
25 | if ! /usr/bin/wget --no-check-certificate ${URLS} -o /tmp/geoip_update_dwn.log; then | |
26 | /usr/bin/logger -t pmacct "Error: Downloading GeoIP database has been failed"; | |
27 | exit 1; | |
28 | /bin/rm -rfv ${WORKDIR}; | |
29 | fi | |
30 | # CleanUP GeoIP dir | |
31 | /bin/rm -rf ${GEOIPDIR}/*.mmdb | |
32 | # Unpack GeoIP mmdb | |
33 | tar xfvz GeoLite2-City.tar.gz --strip 1 --wildcards "**/*.mmdb" | |
34 | # Move GeoIP dats to ntopng | |
35 | /bin/mv ./*.mmdb ${GEOIPDIR}/ 2>/dev/null; | |
36 | # Restart ntopng | |
37 | /etc/init.d/pmacct restart; | |
38 | # Write to messages | |
39 | /usr/bin/logger -t pmacct "GeoIP database has been updated"; | |
40 | # CleanUP | |
41 | /bin/rm -rf ${WORKDIR} 2>/dev/null; | |
42 | ||
43 | # EOF | |
44 |