4

I have tried a couple of suggestions but always failed. I want to get a php file runned almost every minute, for this I am using the command:

*   *   *   *   *   wget http://link.php

How can I give that command a random delay?

For example,

1st time : working in 65th second

2nd time : working in 67th second

3rd time : working in 72nd second

Berque Cemilian
  • 189
  • 1
  • 2
  • 11
  • 3
    What if you add `sleep $[ ( $RANDOM % 60 ) + 1 ]s`? This way, you sleep a random number of seconds and after that perform the command: `* * * * * sleep $[ ( $RANDOM % 10 ) + 1 ]s && wget http://link.php` – fedorqui Sep 04 '14 at 08:10
  • Take a look at [this thread](http://stackoverflow.com/questions/9049460/cron-jobs-and-random-times-within-giving-hours/). – Micah Elliott Jan 15 '16 at 16:53
  • 1
    @fedorqui'SOstopharming' "fun" fact: the `%` sign is special in crontabs: https://serverfault.com/a/274480/236916 - you'd probably have to do `$[ ( $RANDOM \% 60 ) + 1]s` – mwfearnley Nov 03 '20 at 12:39
  • @mwfearnley oh, true, so it needs escaping. In fact [I posted about it](https://stackoverflow.com/a/27125439/1983854) some time ago, a bit after posting the comment here. – fedorqui Nov 03 '20 at 12:40

0 Answers0