Random3
September 13, 2020, 3:14am
#1
Hi!
Before executing a job in cron, I need to pause randomly. I found a construction like this:
0 10 * * * sleep $(( RANDOM % 30 )); wifi down
But it doesn't work for me. In the logs, I see that there was no pause:
Sun Sep 13 10:00:00 2020 cron.info crond[11929]: USER root pid 11940 cmd sleep $(( RANDOM % 30 )); wifi down
...
Sun Sep 13 10:00:01 2020 daemon.notice hostapd: wlan0: AP-DISABLED
How can i do this?
1 Like
Random3:
$(( RANDOM % 30 ))
$(awk 'BEGIN{srand();print int(rand()*30)}')
1 Like
Random3
September 13, 2020, 4:15am
#4
I'm not familiar with awk, does this construct do the same thing?
Random3
September 16, 2020, 9:35am
#7
For three days of use, I noticed that the pause never exceeded 1 hour, despite the set 3 hours. Any ideas and solutions?
Random3
September 16, 2020, 10:22am
#9
No, I am indicating the time in seconds.
1 Like
vgaetera
September 16, 2020, 10:25am
#10
Can you show the current config?
Random3
September 16, 2020, 10:29am
#11
0 0 * * * sleep $(awk 'BEGIN{srand();print int(rand()*10800)}'); wifi down
0 5 * * * sleep $(awk 'BEGIN{srand();print int(rand()*7200)}'); wifi up
1 Like
vgaetera
September 16, 2020, 10:51am
#12
Try the following sleep
version instead of the default BusyBox applet:
https://openwrt.org/packages/pkgdata/coreutils-sleep
Random3
September 16, 2020, 11:29am
#13
Do I only need to install this package?
1 Like
vgaetera
September 16, 2020, 11:32am
#14
Yep, then you can verify:
> readlink -f $(type -p sleep)
/usr/bin/gnu-sleep
> sleep --help
Usage: sleep NUMBER[SUFFIX]...
or: sleep OPTION
Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default),
'm' for minutes, 'h' for hours or 'd' for days. Unlike most implementations
that require NUMBER be an integer, here NUMBER may be an arbitrary floating
point number. Given two or more arguments, pause for the amount of time
specified by the sum of their values.
Random3
September 16, 2020, 11:54am
#15
Now do I need to rewrite the cron rules? But I don't find examples of what I need.
system
closed
September 26, 2020, 11:54am
#16
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.