# Randomize time of cron's PiHole -g process for getting all files

**URL:** <https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452>\
**Category:** Implemented\
**Created:** [August 11, 2017, 10:52am UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452 "2017-08-11T10:52:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![eejeel](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/e/d07c76/32.png) [@eejeel](https://discourse.pi-hole.net/u/eejeel)\
**Post date:** [August 11, 2017, 10:52am UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/1 "2017-08-11T10:52:28Z")

</div>

Several times I see in my log that the automatic gravity update on Sunday 1'59" gives a Status 000 (List download failed, using cached list (list not updated!)) error.  
The cause for this that in a time zone all PiHoles, located in that time zone, access the webservers, mentioned in the adlist at the same time (_exact the same minute !!!_). And weak servers (f.i. zeustracker.abuse.ch) cannot handle more then 1000 requests for the block-file.  
I have solved this by changing the time (only minutes) manually and after that no problems like this.

Is it possible that when the Pihole is updated (pihole -up), the cron task pihole gets a random time for the minutes by the PiHole -up process? Thus in every update process a new random time (only minutes) is stored in the pihole cron task. Advantage is that all PiHole have a different time for running the automatic gravity process

---

<div class="post-metadata">

**Author:** ![spacemonkey](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@spacemonkey](https://discourse.pi-hole.net/u/spacemonkey)\
**Post date:** [August 13, 2017, 2:23pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/2 "2017-08-13T14:23:02Z")

</div>

I have your exact fame feeling about this. I also update once a week or two if possible. Could caring too much be a bad thing? 😃  
Unfortunately I can't vote anymore. I have voted only like less than ten times.

The good news is the the pi-hole script has curl command-switch option that will download only if the timestamp in the http header is newer than the downloaded one. Bad news is github raw files don't have http headers and therefore get downloaded every time.

---

<div class="post-metadata">

**Author:** ![jacob.salmela](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/jacob.salmela/32/8_2.png) [@jacob.salmela](https://discourse.pi-hole.net/u/jacob.salmela)\
**Post date:** [August 31, 2017, 3:22am UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/3 "2017-08-31T03:22:54Z")

</div>

This is actually an interesting feature request, and probably would not pose a problem if our userbase was small, but we are beginning to grow so I suppose it is possible. I personally haven't heard of this happening to anyone else, but I can see it happening. It may be worth while to randomize the time--even by a few minutes--to be a respectful netizen.

---

<div class="post-metadata">

**Author:** ![eejeel](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/e/d07c76/32.png) [@eejeel](https://discourse.pi-hole.net/u/eejeel)\
**Post date:** [September 1, 2017, 8:26pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/4 "2017-09-01T20:26:49Z")

</div>

I discover this by writing the logging of updateGravity into a logfile and mailing this file to me.

Therefore change in Cron (in directory /etc/cron.d/pihole):  
59 1 \* \* 7 root PATH="$PATH:/usr/local/bin/" pihole updateGravity \>/var/log/updateGravity.log

I also have done this for a piHole for family including mailing.  
In both cases I saw the problem: a "Status 000" error during the updateGravity process with the same web server.

I think the easiest way of implementation is: take the minutes part of the time of installation/upgrading the PiHole and put this in the cron task time instead of 59.  
This is not real "random" but gives a big spread of the cron task 'PATH="$PATH:/usr/local/bin/" pihole updateGravity'  
until everybody enable the auto update cron task!! 😉

---

<div class="post-metadata">

**Author:** ![deHakkelaar](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dehakkelaar/32/674_2.png) [@deHakkelaar](https://discourse.pi-hole.net/u/deHakkelaar)\
**Post date:** [September 2, 2017, 8:24am UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/5 "2017-09-02T08:24:49Z")

</div>

Could do a sleep on cron or the script (5min=300s):

`sleep $((RANDOM % 300))`

---

<div class="post-metadata">

**Author:** ![DL6ER](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dl6er/32/281_2.png) [@DL6ER](https://discourse.pi-hole.net/u/DL6ER)\
**Post date:** [October 21, 2017, 2:00pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/6 "2017-10-21T14:00:17Z")

</div>

We have an open pull request for this feature

[https://github.com/pi-hole/pi-hole/pull/1747](https://github.com/pi-hole/pi-hole/pull/1747)

---

<div class="post-metadata">

**Author:** ![deHakkelaar](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dehakkelaar/32/674_2.png) [@deHakkelaar](https://discourse.pi-hole.net/u/deHakkelaar)\
**Post date:** [October 21, 2017, 3:00pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/7 "2017-10-21T15:00:17Z")

</div>

Between 2 and 4 AM in the morning.  
Sounds reasonable.  
Next feature request will be to set times using the UI 😉

EDIT: I just now run the sed and now have:

`55 2 * * 7 root PATH="$PATH:/usr/local/bin/" pihole updateGravity`

---

<div class="post-metadata">

**Author:** ![eejeel](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/e/d07c76/32.png) [@eejeel](https://discourse.pi-hole.net/u/eejeel)\
**Post date:** [October 21, 2017, 7:23pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/8 "2017-10-21T19:23:13Z")

</div>

I agree with deHakkelaar: between 2 and 4 AM in the morning

---

<div class="post-metadata">

**Author:** ![eejeel](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/e/d07c76/32.png) [@eejeel](https://discourse.pi-hole.net/u/eejeel)\
**Post date:** [October 29, 2017, 1:36pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/9 "2017-10-29T13:36:43Z")

</div>

In Europe the actual time is changed to winter time.

In case of that I think the random automatic gravity update between 2 and 4 hr. is not so good idea.  
There is a possibility that, when the random cron time is set between 2 and 3 hr, the update will be done 2 times.  
But in March, when changing to summer time the gravity update is never done.

Maybe a time between 3:01 and 5 hr is a better choice  
What do you think?

---

<div class="post-metadata">

**Author:** ![PromoFaux](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/promofaux/32/1545_2.png) [@PromoFaux](https://discourse.pi-hole.net/u/PromoFaux)\
**Post date:** [October 29, 2017, 1:40pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/10 "2017-10-29T13:40:33Z")

</div>

> [@eejeel](#):
>
> Maybe a time between 3:01 and 5 hr is a better choice

Having just dealt with a load of stuff not properly set up for the rollback to UTC, I second this motion!

---

<div class="post-metadata">

**Author:** ![DL6ER](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dl6er/32/281_2.png) [@DL6ER](https://discourse.pi-hole.net/u/DL6ER)\
**Post date:** [October 29, 2017, 2:39pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/11 "2017-10-29T14:39:45Z")

</div>

I concur. I modified the pull request accordingly.

---

<div class="post-metadata">

**Author:** ![DL6ER](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dl6er/32/281_2.png) [@DL6ER](https://discourse.pi-hole.net/u/DL6ER)\
**Post date:** [October 29, 2017, 3:36pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/12 "2017-10-29T15:36:05Z")

</div>

This has been implemented and will be available in Pi-hole core v3.2.

---

<div class="post-metadata">

**Author:** ![DL6ER](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dl6er/32/281_2.png) [@DL6ER](https://discourse.pi-hole.net/u/DL6ER)\
**Post date:** [October 29, 2017, 3:36pm UTC](https://discourse.pi-hole.net/t/randomize-time-of-crons-pihole-g-process-for-getting-all-files/4452/13 "2017-10-29T15:36:08Z")

</div>

Closed on October 29, 2017, 3:36pm UTC


