Custom Task Scheduling for SMART and Scrubs

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Hi All,

I'm struggling to understand how to set up the following using the custom scheduler options when defining SMART tasks. What I would like is something like the following:

1. Short smart test run every other week on Saturday at 3AM
2. Long smart test run every last Saturday of the month at 10PM

It doesn't look like this is possible.

Thanks,
Fab
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
It is possible in both cases, but you need to understand how crontabs work. From the man page:

Code:
     The format of a cron command is very much the V7 standard, with a number
     of upward-compatible extensions.  Each line has five time and date
     fields, followed by a user name (with optional ``:<group>'' and
     ``/<login-class>'' suffixes) if this is the system crontab file, followed
     by a command.  Commands are executed by cron(8) when the minute, hour,
     and month of year fields match the current time, and when at least one of
     the two day fields (day of month, or day of week) matches the current
     time (see ``Note'' below).  cron(8) examines cron entries once every
     minute.  The time and date fields are:

           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)

     A field may be an asterisk (*), which always stands for ``first-last''.

     Ranges of numbers are allowed.  Ranges are two numbers separated with a
     hyphen.  The specified range is inclusive.  For example, 8-11 for an
     ``hours'' entry specifies execution at hours 8, 9, 10 and 11.

     Lists are allowed.  A list is a set of numbers (or ranges) separated by
     commas.  Examples: ``1,2,5,9'', ``0-4,8-12''.

     Step values can be used in conjunction with ranges.  Following a range
     with ``/<number>'' specifies skips of the number's value through the
     range.  For example, ``0-23/2'' can be used in the hours field to specify
     command execution every other hour (the alternative in the V7 standard is
     ``0,2,4,6,8,10,12,14,16,18,20,22'').  Steps are also permitted after an
     asterisk, so if you want to say ``every two hours'', just use ``*/2''.

     Names can also be used for the ``month'' and ``day of week'' fields.  Use
     the first three letters of the particular day or month (case does not
     matter).  Ranges or lists of names are not allowed.


In both cases, you're going to be working with the 3rd field. In the 1st case, you should use */14 (every 2 weeks, which is 14 days). In the 2nd case, the last Saturday can only occur in the range 24-31.
  1. every other week on Saturday at 3AM: 0 3 */14 * Sat
  2. every last Saturday of the month at 10PM: 0 22 24-31 * Sat
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Hi Samuel,

Sorry, I should have added some context. I do understand how cron works but the scheduler does not show me what I expect to see.

Taking my second example, please see that attached screen shots and let me know what I'm doing wrong. I'm clearly missing something! The second image seems to be suggesting this is due to run on every Saturday as well as between the days 24-31. Should I just trust the output from screenshot 1?
 

Attachments

  • Screenshot 2020-07-25 at 21.07.45.png
    Screenshot 2020-07-25 at 21.07.45.png
    282.4 KB · Views: 284
  • Screenshot 2020-07-25 at 21.08.20.png
    Screenshot 2020-07-25 at 21.08.20.png
    925.3 KB · Views: 276

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
Yes, this appears to be a display bug with the calendar scheduler. FYI, I got the calculation slightly wrong, and the days should be 25-31.
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Thanks Samuel. I'll raise a bug ticket for this.

And thanks re the correction!
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Actually, the date range is susceptible to failure as the 24th can be the last Saturday of a month (e.g. in April 2021) and therefore wouldn't run.

I guess there is no way of entering a script for the day of the week? Then I could use the 'date' command to do this.
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
How about 24-31/7?
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Ideally what I would like is to be able to do is something like the following (although I still need to verify if it's actually correct). This *should* do the last Saturday of the month.... if I haven't messed up my syntax.

0 3 * * 6 [ "$(date -d "+7 day" +%m)" -eq "$(date +%m)" ] && $cmd
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
If cron isn't doing it for you, you could run a daily script in which you check the date, and then kick off the smartctl -t long against each drive when the date matches.
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Yes, this is a possibility and something I have looked at for other housekeeping task.

Do you happen to know what the S.M.A.R.T. Test task actually does so I can replicate this in my script? Does it just run smartctl -t long /dev/name sequentially or does it do this in parallel? Does it send out an email or does this need to be configured separately?
 

Fab Sidoli

Contributor
Joined
May 15, 2019
Messages
114
Yes, this is a possibility and something I have looked at for other housekeeping task.

Do you happen to know what the S.M.A.R.T. Test task actually does so I can replicate this in my script? Does it just run smartctl -t long /dev/name sequentially or does it do this in parallel? Does it send out an email or does this need to be configured separately?

I've figured this out. I see the entries get written to /etc/local/smartd.conf so I can figure out what my script needs to do.

Thanks.
 
Top