From a20e7f23533f3fde1196680cea3ca1424324a15a Mon Sep 17 00:00:00 2001 From: bolvan <k@vodka.home.kg> Date: Wed, 8 May 2019 08:43:33 +0300 Subject: [PATCH] install_easy : randomize cron time to avoid mass list download --- docs/readme.txt | 4 ++-- install_easy.sh | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/readme.txt b/docs/readme.txt index 715f88a..b9c479e 100644 --- a/docs/readme.txt +++ b/docs/readme.txt @@ -279,7 +279,7 @@ TPWS_OPT_HTTPS="--split-pos=3" /opt/zapret/ipset/get_config.sh Зашедулить задание обновления листа : crontab -e - Создать строчку "0 12 * * */2 /opt/zapret/ipset/get_config.sh" + Создать строчку "0 12 */2 * * /opt/zapret/ipset/get_config.sh" Запустить службу : systemctl start zapret @@ -429,7 +429,7 @@ grep от busybox катастрофически медленный с опци /opt/zapret/ipset/get_config.sh Зашедулить задание обновления листа : crontab -e - Создать строчку "0 12 * * */2 /opt/zapret/ipset/get_config.sh" + Создать строчку "0 12 */2 * * /opt/zapret/ipset/get_config.sh" Включить автозапуск службы и запустить ее : /etc/init.d/zapret enable diff --git a/install_easy.sh b/install_easy.sh index 12f4a64..9d44039 100755 --- a/install_easy.sh +++ b/install_easy.sh @@ -50,6 +50,19 @@ md5file() md5sum "$1" | cut -f1 -d ' ' } +random() +{ + # $1 - min, $2 - max + local r rs + if [ -c /dev/urandom ]; then + read rs </dev/urandom + else + rs="$RANDOM$RANDOM$(date)" + fi + # shells use signed int64 + r=1$(echo $rs | md5sum | sed 's/[^0-9]//g' | head -c 17) + echo $(( ($r % ($2-$1+1)) + $1 )) +} check_system() { @@ -230,6 +243,8 @@ check_location() crontab_add() { + # $1 - hour min + # $2 - hour max [ -x "$GET_LIST" ] && { echo \* adding crontab entry ... @@ -239,7 +254,7 @@ crontab_add() echo some entries already exist in crontab. check if this is corrent : grep "$GET_LIST_PREFIX" $CRONTMP else - echo "0 12 * * */2 $GET_LIST" >>$CRONTMP + echo "$(random 0 59) $(random $1 $2) */2 * * $GET_LIST" >>$CRONTMP crontab $CRONTMP fi @@ -381,7 +396,8 @@ install_systemd() install_sysv_init register_sysv_init_systemd download_list - crontab_add + # desktop system : likely it will be up at daytime + crontab_add 9 21 service_start_systemd } @@ -557,7 +573,8 @@ install_openwrt() install_sysv_init register_sysv_init download_list - crontab_add + # router system : works 24/7. night is the best time + crontab_add 0 6 service_start_sysv install_openwrt_firewall restart_openwrt_firewall