0

There is a python script that I want to run as a cronjob with a given probability.

Lets say I want to run that file at after reboot. Thus, using @reboot /path/to/file

I don't know whether setting a probability is possible with cronjobs. Currently I'm using another python script to run the desired script. Is there a better way to do this?

1 Answers1

0

Add a probability call to the Python script.

import sys
from random import random

run_script_prob = 0.3

if random() > run_script_prob:
    sys.exit(0)
James
  • 32,991
  • 4
  • 47
  • 70
  • Yes exactly. I'm using something similar to [this](https://stackoverflow.com/a/1186847/15079222). But I am asking if there is a way to do this directly with cron. – Linda Tabatha Forester Mar 21 '21 at 13:26