I need the ability to run a PHP script 20 times a day at completely random times. I also want it to run only between 9am - 11pm.
I\'m familiar with creating cron job
at -f [file] [timespec]
or
echo [command] | at [timespec]
or
at [timespec] ... and interactive specification
like script's recording.
At runs the text provide on stdin or in the file specified by -f [file].
Here's the [timespec] grammar. It can be something like:
0100, 2359, 1620now + 10 minutes2071-05-31 - 5 hours 12 minutes UTCIf you're explicitly specifying the timezone, some versions of the timespec might only allow UTC for the optional timezone argument.
cat script.sh | at now + $(($RANDOM % 10)) hours $(($RANDOM % 60)) minutes
at -f script.sh now + $(($RANDOM % 10)) hours $(($RANDOM % 60)) minutes
You can test the bash parsing by pre-pending echo and escaping the | (pipe).
echo cat script.sh \| at now + $(($RANDOM % 10)) hours $(($RANDOM % 60)) minutes
echo at -f script.sh now + $(($RANDOM % 10)) hours $(($RANDOM % 60)) minutes
To see jobs scheduled, use atq and job contents (environment vars, setup, and command/script) with at -c [jobid].
The system is part of cron, and the interactive prompt actually captures the whole current state of your shell, so you can run commands without specifying absolute paths.