OPNsense Forum

Archive => 20.1 Legacy Series => Topic started by: xofer on March 01, 2020, 11:19:28 am

Title: Cron weekdays ambiguousness
Post by: xofer on March 01, 2020, 11:19:28 am
How are the weekdays numbered in the cron jobs?

0-6 or 1-7 (is Sunday the first or last day of the week)?
or 0-7 (where 0 and 7 is understood as Sunday) like in the system?

It would make my mind at ease if there was an explanation in the GUI help. Currently it says "Enter the days of the week for the job to act, can also be a comma-separated list, * (each) or a range (ex. 1,2,3 or 1-3)"
Title: Re: Cron weekdays ambiguousness
Post by: siga75 on March 01, 2020, 12:13:44 pm
in most unix systems both 0 and 7 are sunday, I suppose it's the same for freeBSD
Title: Re: Cron weekdays ambiguousness
Post by: chemlud on March 01, 2020, 05:43:39 pm
https://crontab.guru/#0_2_*_*_7

https://crontab.guru/#0_2_*_*_0
Title: Re: Cron weekdays ambiguousness
Post by: xofer on March 01, 2020, 09:48:06 pm
in most unix systems both 0 and 7 are sunday, I suppose it's the same for freeBSD
Yes, that is also what I assumed, but it would be nice if it was evident from GUI help itself.
Title: Re: Cron weekdays ambiguousness
Post by: Alphabet Soup on March 02, 2020, 01:00:36 am
When I first configure a cron job on a server, I usually also paste in these explanatory lines from 'man 5 crontab'.  Prefixed with #'s so they are just comments to cron, the result is this:

Code: [Select]
# field         allowed values
# -----         --------------
# minute        0-59
# hour          0-23
# day of month  1-31
# month         1-12 (or names, see below)
# day of week   0-7 (0 or 7 is Sun, or use names)

There's more info in the man page (of course... that's why it's a man page), but the above bit is enough to remind me of the number, order, and meaning of the time and date fields.  Having it right there in the crontab also means it's viewable whether you're editing cron jobs in the GUI or CLI.
Title: Re: Cron weekdays ambiguousness
Post by: xofer on March 02, 2020, 02:14:01 am
Lets try to explain the issue again.
I know how crontab file as such works. I can also do #man 5 crontab
That is not the issue here.

I am talking about a web GUI here. There is no guarantee that it behaves like a crontab file. It would be nice if that was obvious from the GUI itself without trial and error and assumptions.

(https://bayimg.com/3c64b24b89bfb6891611b424554cfc73e5ea2c1f.jpg)
Title: Re: Cron weekdays ambiguousness
Post by: siga75 on March 02, 2020, 07:29:24 am
it's quite obvious that those entries goes in a standard crontab...

[root@myfw /var/cron/tabs]# crontab -l
# or /usr/local/etc/cron.d and follow the same format as
# /etc/crontab, see the crontab(5) manual page.
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
#minute hour    mday    month   wday    command
1       *       *       *       *       (/usr/local/sbin/expiretable -v -t 3600 webConfiguratorlockout) > /dev/null
2       *       *       *       *       (/usr/local/sbin/expiretable -v -t 3600 sshlockout) > /dev/null
3       *       *       *       *       (/usr/local/sbin/expiretable -v -t 3600 virusprot) > /dev/null
5       *       *       *       *       (/usr/local/etc/rc.expireaccounts) > /dev/null
*/4     *       *       *       *       (/usr/local/sbin/ping_hosts.sh) > /dev/null
0       */2     *       *       *       (/usr/local/etc/rc.syshook.d/backup/20-dhcpleases) > /dev/null
0       1       *       *       *       (configctl system remote backup) > /dev/null
*       *       *       *       *       (/usr/local/opnsense/scripts/nginx/ngx_autoblock.php) > /dev/null
1       3       *       *       0       (configctl filter schedule bogons) > /dev/null
*       *       *       *       *       (/usr/local/bin/flock -n -E 0 -o /tmp/filter_update_tables.lock /usr/local/opnsense/scripts/filter/update_tables.py) > /dev/null


[root@myfw /var/cron/tabs]# crontab -l -u nobody
# or /usr/local/etc/cron.d and follow the same format as
# /etc/crontab, see the crontab(5) manual page.
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
#minute hour    mday    month   wday    command
# Origin/Description: IDS/ids rule updates
15      0       *       *       *       /usr/local/sbin/configctl ids update
# Origin/Description: cron/ban attacking hosts
*/5     *       *       *       *       /usr/local/sbin/configctl nginx autoblock
# Origin/Description: cron/auto update firmware
45      2       *       *       *       /usr/local/sbin/configctl firmware auto-update
# Origin/Description: cron/purge nginx ban
30      4       *       *       *       /usr/local/sbin/configctl nginx-ban-purge clean
# Origin/Description: cron/update aliases
*/5     *       *       *       *       /usr/local/sbin/configctl filter refresh_aliases
# Origin/Description: AcmeClient/AcmeClient Cronjob for Certificate AutoRenewal
0       0       *       *       *       /usr/local/sbin/configctl acmeclient cron-auto-renew
# Origin/Description: Proxy/fetch proxy acls
0       0       *       *       1       /usr/local/sbin/configctl proxy fetchacls
# Origin/Description: Sensei/Sensei periodicals
*       *       *       *       *       /usr/local/sbin/configctl sensei periodicals > /dev/null 2>&1
Title: Re: Cron weekdays ambiguousness
Post by: Alphabet Soup on March 02, 2020, 10:01:01 am
Now I see what you mean.

The help text for each of the five time & date fields is essentially the same and sufficient for most cases.  But where most people can probably map "July" to "7", it is not so obvious that "Wednesday" is "3", and you're asking if someone could improve the help text for "Days of the week" to include this non-obvious mapping.  Or at least hint that words like "wed" or "thu" could be used instead.  Uncertainty about the mapping for users who aren't so familiar with cron and from users (like yourself) who are familiar enough to wonder if the GUI might have it's own user-friendly-and-different expectation of input.

Would you propose something like:
"Enter the days of the week for the job to act, can also be a comma-separated list, * (each) or a range (ex. 1,2,3 or 1-3) where 0 or 7 is Sun"

Or some static text at the top of the entire form saying something like:
"The settings you save here will be added directly to your crontab file.  For details, see 'man 5 crontab'."

Or something else?