2

according to crontab.guru, many functions like @reboot, @daily, @annually ... are not standard. Is there any way to know the one implemented on my system (Kubuntu 21.04) ? I have tried the man-page, but have no result.

Thank you

dmx
  • 1,977
  • 1
    way to know the one implemented on my system ? ... I guess we are supposed to know what your system is? – David Aug 18 '21 at 09:19
  • 3
    The best way to check is just to try it. Use with @reboot something that you can easily check for, for example create a particular file. If it works, then @reboot is supported. BTW. According to this: https://askubuntu.com/questions/335615/does-ubuntu-support-reboot-in-crontab , @reboot is supported on Ubuntu at least since 16.04, so it should be supported on Kubuntu as well. Also try man 5 crontab and see if it mentions @reboot. – raj Aug 18 '21 at 09:31

1 Answers1

7

The supported "special strings" for time specification are listed in man 5 crontab:

   Instead  of the first five fields, one of eight special strings may ap‐
   pear:
      string         meaning
      ------         -------
      @reboot        Run once, at startup.
      @yearly        Run once a year, "0 0 1 1 *".
      @annually      (same as @yearly)
      @monthly       Run once a month, "0 0 1 * *".
      @weekly        Run once a week, "0 0 * * 0".
      @daily         Run once a day, "0 0 * * *".
      @midnight      (same as @daily)
      @hourly        Run once an hour, "0 * * * *".

Please note that startup, as far as @reboot is concerned, is the time when the cron(8) daemon startup. In particular, it may be before some system daemons, or other facilities, were startup. This is due to the boot order sequence of the machine.

If you don't believe the documentation for your system, then you may download the source (ex. apt-get source cron) and check the entry.c file:

cron-3.0pl1$ grep '!strcmp' entry.c
                if (!strcmp("reboot", cmd)) {
                } else if (!strcmp("yearly", cmd) || !strcmp("annually", cmd)){
                } else if (!strcmp("monthly", cmd)) {
                } else if (!strcmp("weekly", cmd)) {
                } else if (!strcmp("daily", cmd) || !strcmp("midnight", cmd)) {
                } else if (!strcmp("hourly", cmd)) {
steeldriver
  • 136,215
  • 21
  • 243
  • 336