<div dir="ltr">Hi Everyone,<div><br></div><div>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.</div><div><br></div><div>I added the following to my crontab setup:</div><div><font face="monospace, monospace">PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin</font><br></div><div><br></div><div>This script is now kicking off properly and my duration variable is properly getting set because smartctl is now found.</div><div><br></div><div>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].</div><div><br></div><div>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.</div><div><br></div><div>-Ubence</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jul 5, 2018 at 3:17 PM Ubence Quevedo <<a href="mailto:thatrat@gmail.com">thatrat@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi to anyone still tuned in on this smartctl thread...<div><br></div><div>I created a script [which I'm sure could be a bit better]:</div><div><div><font face="monospace, monospace">#!/bin/bash</font></div><div><font face="monospace, monospace"># Starting</font></div><div><font face="monospace, monospace">echo Starting at `date`</font></div><div><font face="monospace, monospace"># Running a long smartctl test against /dev/disk0</font></div><div><font face="monospace, monospace">smartctl -t force -t long /dev/disk0 > /dev/null</font></div><div><font face="monospace, monospace"># Running a long smartctl test against /dev/disk2</font></div><div><font face="monospace, monospace">smartctl -t force -t long /dev/disk2 > /Users/uquevedo/bin/smart_long.txt</font></div><div><font face="monospace, monospace"># Setting duration variable against number of minutes from smartctl test output</font></div><div><font face="monospace, monospace">duration=`grep Please /Users/uquevedo/bin/smart_long.txt | awk '{print $3}'`</font></div><div><font face="monospace, monospace"># Echoing duration</font></div><div><font face="monospace, monospace">echo $duration</font></div><div><font face="monospace, monospace"># Caffeinating sleep to keep system awak for smartctl long test to run, also adding 10 minutes to test duration</font></div><div><font face="monospace, monospace">echo "Sleeping for $((duration * 60 + 600)) seconds so long smartctl can run to completion..."</font></div><div><font face="monospace, monospace">caffeinate -i -m sleep `echo $((duration * 60 + 600))`</font></div><div><font face="monospace, monospace"># Cleaning up tmp file</font></div><div><font face="monospace, monospace">rm -vf /Users/uquevedo/bin/smart_long.txt</font></div><div><font face="monospace, monospace"># Finished</font></div><div><font face="monospace, monospace">echo Finished at `date`</font></div></div><div><br></div><div>The script is kicked off from the following cron entries for my user account:</div><div><div><font face="monospace, monospace">#Tell system at 12:01AM to turn on smart info</font></div><div><font face="monospace, monospace">01 00 * * * smartctl -s on /dev/disk0</font></div><div><font face="monospace, monospace">01 00 * * * smartctl -s on /dev/disk2</font></div><div><font face="monospace, monospace">#Script to run smartctl long test at 12:02AM with caffeinate to keep system awake for the test</font></div><div><font face="monospace, monospace">02 00 * * * sh /Users/uquevedo/bin/smart_long.sh >> /Users/uquevedo/.smart_long</font></div><div><font face="monospace, monospace">#Tell system at 12:01PM to turn on smart info</font></div><div><font face="monospace, monospace">01 12 * * * smartctl -s on /dev/disk0</font></div><div><font face="monospace, monospace">01 12 * * * smartctl -s on /dev/disk2</font></div><div><font face="monospace, monospace">#Script to run smartctl long test at 12:02PM with caffeinate to keep system awake for the test</font></div><div><font face="monospace, monospace">02 12 * * * sh /Users/uquevedo/bin/smart_long.sh >> /Users/uquevedo/.smart_long</font></div></div><div><br></div><div>Which in turn are kicked off by root level cron jobs that wake the system at midnight and noon:</div><div><div><font face="monospace, monospace">#Tell system to wake at 12:00PM</font></div><div><font face="monospace, monospace">00 12 * * * pmset repeat wakeorpoweron MTWRFSU 23:59:00</font></div><div><span style="font-family:monospace,monospace">#Tell system to wake at Midnight</span><br></div><div><font face="monospace, monospace">00 00 * * * pmset repeat wakeorpoweron MTWRFSU 11:59:00</font></div><div><br></div></div><div>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.</div><div><br></div><div>However, when this script is kicked off through cron, the redirected output from the <span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">longest smartctl command creates a blank file which in turn only makes for a 10 minute sleep instead of the desired length of sleep.</span></div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Anyone have any ideas why this is?  What am I missing or not taking into account for?</div><div><br></div><div>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.</div><div><br></div><div>-Ubence</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 29, 2018 at 6:06 AM Ubence Quevedo <<a href="mailto:thatrat@gmail.com" target="_blank">thatrat@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Definitely going to give the sleep thing a try.<div><br></div><div>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.</div><div><br></div><div>I'd still love it if Apple would just allow selective span test ranges instead of just short and long tests.</div><div><br></div><div>-Ubence</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 29, 2018 at 5:36 AM Rainer Müller <<a href="mailto:raimue@macports.org" target="_blank">raimue@macports.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2018-06-29 10:03, Ryan Schmidt wrote:<br>
> <br>
> On Jun 28, 2018, at 19:43, Ubence Quevedo wrote:<br>
> <br>
>> 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.<br>
> <br>
> 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.<br>
> <br>
> 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):<br>
> <br>
> caffeinate -i sleep 12420<br>
> <br>
> ("sleep" in this context means "wait this many seconds").<br>
<br>
You can just start caffeinate without any arguments in a separate<br>
terminal window to prevent the system from sleeping until you kill the<br>
process (with Ctrl-C).<br>
<br>
Rainer<br>
</blockquote></div>
</blockquote></div>
</blockquote></div>