| verzia 1.11, 2015/08/27 06:16:20 |
verzia 1.12, 2017/09/16 09:36:22 |
|
|
| # |
# |
| # download.sh |
# download.sh |
| # |
# |
| # Developed by Ondrej Jombik <nepto@platon.sk> |
# Developed by Ondrej Jombik <jombik@platon.org> |
| # Copyright (c) 2006 Platon Group, http://platon.sk/ |
# Copyright (c) 2006-2017 Platon Group, http://platon.sk/ |
| # Licensed under terms of GNU General Public License. |
# Licensed under terms of GNU General Public License. |
| # All rights reserved. |
# All rights reserved. |
| # |
# |
| # Changelog: |
# Changelog: |
| # 2006-08-13 - created |
# 2006-08-13 - created |
| |
# 2017-09-12 - implemented new SK-NIC-EPP/CentralNic export |
| # |
# |
| |
|
| # $Platon: scripts/php/sk-nic/download.sh,v 1.10 2010-07-05 18:08:26 nepto Exp $ |
# $Platon: scripts/php/sk-nic/download.sh,v 1.11 2015/08/27 06:16:20 nepto Exp $ |
| |
|
| # |
# |
| # Put this into your crontab, it will run this script every morning at 6:15 am: |
# Put this into your crontab, it will run this script every morning at 6:15 am: |
|
|
| # NOTE: you will probably need to alter the script path |
# NOTE: you will probably need to alter the script path |
| # |
# |
| |
|
| # |
PROCESS_FILE="$1"; |
| # TODO: symlinking sk-nic.current.csv |
|
| # |
|
| |
|
| PREFIX="SK-NIC"; |
PREFIX="SK-NIC"; |
| PREFIX_ERR="$PREFIX-ERROR"; |
PREFIX_ERR="$PREFIX-ERROR"; |
| INPUT_FILE="https://www.sk-nic.sk/documents/domeny_1.txt.gz"; |
INPUT_FILE="https://sk-nic.sk/subory/domains.txt"; |
| OUTPUT_FILE="data/sk-nic.`date '+%F'`.csv"; |
OUTPUT_FILE="data-new/sk-nic.`date '+%F'`.csv"; |
| WORK_FILE="domeny.gz"; |
WORK_FILE="domains-work-file.csv"; |
| WGET="`which wget`"; |
WGET="`which wget`"; |
| PHP="`which php`"; |
PHP="`which php`"; |
| |
|
| work_dir="`dirname $0`"; |
work_dir="`dirname $0`"; |
| if [ "X$work_dir" = "X" ]; then |
if [ "X$work_dir" = "X" ]; then |
| echo "$PREFIX_ERR: empty work directory variable"; |
echo "$PREFIX_ERR: empty work directory variable"; |
| exit 8; |
exit 1; |
| fi; |
fi; |
| |
|
| cd "$work_dir"; |
cd "$work_dir"; |
| if [ "$?" -ne 0 ]; then |
if [ "$?" -ne 0 ]; then |
| echo "$PREFIX_ERR: unable to change directory"; |
echo "$PREFIX_ERR: unable to change directory"; |
| exit 8; |
|
| fi; |
|
| |
|
| if [ -z "$WGET" ]; then |
|
| echo "$PREFIX_ERR: wget binary not found"; |
|
| exit 2; |
exit 2; |
| fi; |
fi; |
| |
|
| if [ -s "$OUTPUT_FILE" ]; then |
# if no file provided, download one from www.sk-nic.sk |
| echo "$PREFIX_ERR: File already exists: $OUTPUT_FILE"; |
if [ -z "$PROCESS_FILE" ]; then |
| exit 1; |
if [ -z "$WGET" ]; then |
| fi; |
echo "$PREFIX_ERR: wget binary not found"; |
| |
exit 3; |
| $WGET --quiet -O "$WORK_FILE" --no-check-certificate "$INPUT_FILE" \ |
fi; |
| && zcat "$WORK_FILE" > "$OUTPUT_FILE"; |
if [ -s "$OUTPUT_FILE" ]; then |
| |
echo "$PREFIX_ERR: file already exists: $OUTPUT_FILE"; |
| |
exit 4; |
| |
fi; |
| |
|
| |
$WGET --quiet -O "$OUTPUT_FILE" --no-check-certificate "$INPUT_FILE"; |
| |
rc="$?"; |
| |
|
| |
if [ "$rc" -eq 8 ]; then |
| |
echo "$PREFIX_ERR: error 404 Not Found - repeat download"; |
| |
exit $?; |
| |
elif [ "$rc" -ne 0 ]; then |
| |
echo "$PREFIX_ERR: fetch error (wget_exit:$rc; wget_bin:$WGET)"; |
| |
exit $?; |
| |
fi; |
| |
|
| |
if [ \! -s "$OUTPUT_FILE" ]; then |
| |
echo "$PREFIX_ERR: file $OUTPUT_FILE was downloaded, but it is empty"; |
| |
exit 5; |
| |
fi |
| |
|
| if [ "$?" -ne 0 ]; then |
PROCESS_FILE="$OUTPUT_FILE"; |
| echo -ne "$PREFIX_ERR: wget error, see below (wget is $WGET):\n\n"; |
fi |
| $WGET -O "$WORK_FILE" --no-check-certificate "$INPUT_FILE"; |
|
| # pass the exit code from wget |
|
| exit $?; |
|
| fi; |
|
| |
|
| if [ -z "$PHP" ]; then |
if [ -z "$PHP" ]; then |
| echo "$PREFIX_ERR: php binary not found, no import was done"; |
echo "$PREFIX_ERR: php binary not found, no import was done"; |
| exit 4; |
exit 6; |
| fi; |
fi; |
| |
|
| # and now real import |
# and now real import |
| $PHP sk-nic.php "$OUTPUT_FILE" |
$PHP sk-nic.php "$PROCESS_FILE" |
| rc="$?"; |
rc="$?"; |
| if [ "$rc" -ne 0 ]; then |
if [ "$rc" -ne 0 ]; then |
| echo "ERROR: return code from sk-nic.php: $rc" >/dev/stderr; |
echo "ERROR: return code from sk-nic.php: $rc" >/dev/stderr; |
|
|
| #echo "THESE FILES WAS DELETED BY AUTOMATED PROCESS:"; |
#echo "THESE FILES WAS DELETED BY AUTOMATED PROCESS:"; |
| #echo "---------------------------------------------"; |
#echo "---------------------------------------------"; |
| #find data/ -maxdepth 1 -type f -name 'sk-nic.*.csv' -mtime +10 |
#find data/ -maxdepth 1 -type f -name 'sk-nic.*.csv' -mtime +10 |
| find data/ -maxdepth 1 -type f -name 'sk-nic.*.csv' -mtime +10 -exec rm -f {} \; |
#find data/ -maxdepth 1 -type f -name 'sk-nic.*.csv' -mtime +10 -exec rm -f {} \; |
| |
|