smartctl - Can't run select span range

Ubence Quevedo thatrat at gmail.com
Fri Jul 6 16:51:35 UTC 2018


Hi Everyone,

I figured out why I wasn't getting any results when my script was being
kicked off by cron.  It was because the path variable that the script was
being launched from cron with didn't have smartctl in it.

I added the following to my crontab setup:
PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin

This script is now kicking off properly and my duration variable is
properly getting set because smartctl is now found.

Now the caffeinate command with sleep is giving me some problems.  I though
I should do the -m option for caffeinate since that would prevent disk
sleep, but that didn't help for the spinning disk in my setup [the smartcl
long test for the SSD ran to completion properly].

I'm going to be playing with this some more, but I think I've got some of
the technical issues worked out, but now need to figure out why caffeinated
sleep isn't working out.

-Ubence

On Thu, Jul 5, 2018 at 3:17 PM Ubence Quevedo <thatrat at gmail.com> wrote:

> Hi to anyone still tuned in on this smartctl thread...
>
> I created a script [which I'm sure could be a bit better]:
> #!/bin/bash
> # Starting
> echo Starting at `date`
> # Running a long smartctl test against /dev/disk0
> smartctl -t force -t long /dev/disk0 > /dev/null
> # Running a long smartctl test against /dev/disk2
> smartctl -t force -t long /dev/disk2 > /Users/uquevedo/bin/smart_long.txt
> # Setting duration variable against number of minutes from smartctl test
> output
> duration=`grep Please /Users/uquevedo/bin/smart_long.txt | awk '{print
> $3}'`
> # Echoing duration
> echo $duration
> # Caffeinating sleep to keep system awak for smartctl long test to run,
> also adding 10 minutes to test duration
> echo "Sleeping for $((duration * 60 + 600)) seconds so long smartctl can
> run to completion..."
> caffeinate -i -m sleep `echo $((duration * 60 + 600))`
> # Cleaning up tmp file
> rm -vf /Users/uquevedo/bin/smart_long.txt
> # Finished
> echo Finished at `date`
>
> The script is kicked off from the following cron entries for my user
> account:
> #Tell system at 12:01AM to turn on smart info
> 01 00 * * * smartctl -s on /dev/disk0
> 01 00 * * * smartctl -s on /dev/disk2
> #Script to run smartctl long test at 12:02AM with caffeinate to keep
> system awake for the test
> 02 00 * * * sh /Users/uquevedo/bin/smart_long.sh >>
> /Users/uquevedo/.smart_long
> #Tell system at 12:01PM to turn on smart info
> 01 12 * * * smartctl -s on /dev/disk0
> 01 12 * * * smartctl -s on /dev/disk2
> #Script to run smartctl long test at 12:02PM with caffeinate to keep
> system awake for the test
> 02 12 * * * sh /Users/uquevedo/bin/smart_long.sh >>
> /Users/uquevedo/.smart_long
>
> Which in turn are kicked off by root level cron jobs that wake the system
> at midnight and noon:
> #Tell system to wake at 12:00PM
> 00 12 * * * pmset repeat wakeorpoweron MTWRFSU 23:59:00
> #Tell system to wake at Midnight
> 00 00 * * * pmset repeat wakeorpoweron MTWRFSU 11:59:00
>
> If I run the smart_long.sh script through an interactive session, the
> sleep command that is looking at the calculated seconds for how long the
> longest smartctl command takes to run works just fine.
>
> However, when this script is kicked off through cron, the redirected
> output from the longest smartctl command creates a blank file which in
> turn only makes for a 10 minute sleep instead of the desired length of
> sleep.
>
> If I were to run a similar script in Linux through a cron job, I don't
> think I'd have this same issue where the redirected output file is a zero
> file.
>
> I've tried a few different redirects of the stdout from the smartctl
> command, but anything run from the cron job non-interactively creates a
> zero file.
>
> Anyone have any ideas why this is?  What am I missing or not taking into
> account for?
>
> Also, given all of the above workaround as another reason I would just
> love the selective span range to just work for smartctl testing, but that's
> an Apple problem.
>
> -Ubence
>
> On Fri, Jun 29, 2018 at 6:06 AM Ubence Quevedo <thatrat at gmail.com> wrote:
>
>> Definitely going to give the sleep thing a try.
>>
>> Since I'm trying to automate this to kick off long smartctl tests at
>> specific times, opening a separate window just for caffeinate won't be very
>> efficient.  I've got some ideas on how to script this out.
>>
>> I'd still love it if Apple would just allow selective span test ranges
>> instead of just short and long tests.
>>
>> -Ubence
>>
>> On Fri, Jun 29, 2018 at 5:36 AM Rainer Müller <raimue at macports.org>
>> wrote:
>>
>>> On 2018-06-29 10:03, Ryan Schmidt wrote:
>>> >
>>> > On Jun 28, 2018, at 19:43, Ubence Quevedo wrote:
>>> >
>>> >> I gave caffeinate a try, and set my system sleep time to a more
>>> reasonable timeout [30 minutes], but since smartctl isn't an interactive
>>> process [a tsr?], the system never stays awake long enough to finish a
>>> whole test.  I even added the -m option to prevent the disk from idle
>>> sleeping but that didn't help.
>>> >
>>> > Oh, right. As I recall, smartctl exits immediately, and the test
>>> occurs on the disk in the background, and you later run smartctl again to
>>> get the result.
>>> >
>>> > In that case, you can run smartctl normally, and then caffeinate a
>>> sleep command that takes at least as long as the test. For example, if the
>>> test will take 206 minutes, you could sleep for 207 minutes (12,420
>>> seconds):
>>> >
>>> > caffeinate -i sleep 12420
>>> >
>>> > ("sleep" in this context means "wait this many seconds").
>>>
>>> You can just start caffeinate without any arguments in a separate
>>> terminal window to prevent the system from sleeping until you kill the
>>> process (with Ctrl-C).
>>>
>>> Rainer
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macports.org/pipermail/macports-users/attachments/20180706/87a5b23d/attachment.html>


More information about the macports-users mailing list