LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   running cron jobs at random times (https://www.linuxquestions.org/questions/linux-software-2/running-cron-jobs-at-random-times-601983/)

fakie_flip 11-23-2007 05:19 PM

running cron jobs at random times
 
How is it possible to run cron jobs at random times?

harry edwards 11-23-2007 05:32 PM

I do not think it's possible; although, you could run a script every so many minutes and code the random element into the script i.e.

#!/bin/sh

# Grab a random value between 0-32767.
value=$RANDOM
if[ $value -lt 240 ]; then
<executed command>
fi

This gives a 240 in 32767 chance of execution.

Geremia 11-15-2017 11:58 AM

Quote:

Originally Posted by fakie_flip (Post 2968840)
How is it possible to run cron jobs at random times?

To run everyday at a random time:
Code:

0 0 * * * sleep `echo $RANDOM/32767*86400 | bc -l`; <command_to_execute>
86400 is the number of seconds in a day, and 32767 is the maximum value $RANDOM can be.

RandomTroll 11-15-2017 12:54 PM

You may want to use at instead. You can schedule an at job by echoing a string into it; ctrl-d is the end. echo -e allows sending special characters.


All times are GMT -5. The time now is 04:46 AM.