# Sleep time

**URL:** <https://community.wd.com/t/sleep-time/95608>\
**Category:** My Cloud OS 3\
**Created:** [March 22, 2015, 2:20am UTC](https://community.wd.com/t/sleep-time/95608 "2015-03-22T02:20:45Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [March 22, 2015, 2:20am UTC](https://community.wd.com/t/sleep-time/95608/1 "2015-03-22T02:20:45Z")

</div>

I’ve been trying to trouble shoot why the disk does not sleep very much.&nbsp; So I wrote this script that

will allow you to see how muvh you drive is sleeping.&nbsp; Just save the follwoing code as sleep.awk then do

tail /var/log/user.log|./sleep.awk.&nbsp; In my case I run this script in the directory that the sleep.awk file is in.&nbsp; The

collums are month day enter sleep time wake up time total sleep time hr:mm:sec.&nbsp; At the end if displays

the total hr:mm"sec that the drive slept.

I how this helps people.

awk ‘{if ($8 ~ /after/){  
hh1=int($9/3600)  
mm1=int(($9%3600)/60)  
ss1=($9%3600)%60  
Total = Total + $9  
printf “%3s %2s %8s %8s %5d %2d:%02d:%02d\n”,$1,$2 ,substr($12,0,9),$3,$9 ,hh1,mm1,ss1}}  
END {  
hh1=int(Total/3600)  
mm1=mm1=int(($9%3600)/60)  
ss1=($9%3600)%60  
printf “Total Sleep Time: %2d:%02d:%02d\n” ,hh1,mm1,ss1 }’

---

<div class="post-metadata">

**Author:** ![jubei04](https://avatars.discourse-cdn.com/v4/letter/j/4da419/32.png) [@jubei04](https://community.wd.com/u/jubei04)\
**Post date:** [March 22, 2015, 7:12pm UTC](https://community.wd.com/t/sleep-time/95608/2 "2015-03-22T19:12:14Z")

</div>

Hello rac8006, thanks for sharing. I would recommend adding a disclaimer to your post since this could possibly void the warranty if not done correctly.&nbsp;In any case be careful while modifying system files.

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [March 22, 2015, 8:07pm UTC](https://community.wd.com/t/sleep-time/95608/3 "2015-03-22T20:07:01Z")

</div>

This changes no system files. It is just a awk script that can be put into the Public directory.&nbsp; You then need to use SSH to run the script.&nbsp; All of which to my knowledge is allowed.

RAC

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [January 4, 2016, 11:21pm UTC](https://community.wd.com/t/sleep-time/95608/4 "2016-01-04T23:21:32Z")

</div>

This is the latest script. Copy the script below as sleep.awk and save it in /nfs/Public. Do not save the start and stop lines. Once this is done all you have to do is ssh into the My Cloud. cd/nfs/Public Then type sh sleeptime.sh. This will list everything you need to know about your device sleeping.

save this line as sleeptime.sh  
cat /var/log/user.log.1 /var/log/user.log|/nfs/Public/sleep.awk

Sleep.awk start  
awk ’  
NR==1 { a=substr($1,6,2); b=substr($1,9,2); c=substr($1,12,8); y=substr($1,1,4)}  
{if ($7 ~ /after/){  
hh1=int($8/3600)  
mm1=int(($8%3600)/60)  
ss1=($8%3600)%60  
Total = Total + $8  
printf “%2s %2s %8s %8s %5d %2d:%02d:%02d\n”,substr($1,6,2),substr($1,9,2) ,substr($11,0,9),substr($1,12,8),$8 ,hh1,mm1,ss1}}  
END {  
hh1=int(Total/3600)  
mm1=mm1=int(($8%3600)/60)  
ss1=($8%3600)%60  
printf “Total Sleep Time: %2d:%02d:%02d\n” ,hh1,mm1,ss1  
start= a “/” b “/” y " " c  
“date +%Y”|getline year  
end= substr($1,6,2) “/” substr($1,9,2) “/” year " " substr($1,12,8)  
$1=start  
cmd=“date --date="”$1"" +%s"  
cmd|getline st  
printf “Start %s\n” ,st  
$1=end  
cmd=“date --date="”$1"" +%s"  
cmd|getline end  
printf “End %s\n” ,end  
Total=end-st  
hh1=int(Total/3600)  
mm1=mm1=int((Total%3600)/60)  
ss1=(Total%3600)%60  
printf “Total Up Time: %2d:%02d:%02d\n” ,hh1,mm1,ss1  
}’  
Sleep.awk stop

---

<div class="post-metadata">

**Author:** ![cpt\_paranoia](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/cpt_paranoia/32/34703_2.png) [@cpt\_paranoia](https://community.wd.com/u/cpt_paranoia)\
**Post date:** [January 5, 2016, 12:21am UTC](https://community.wd.com/t/sleep-time/95608/5 "2016-01-05T00:21:31Z")

</div>

That looks to have suffered from the effects of the forum’s format parser…

And it might be easier if sleep.awk were a simple AWK script, called using ‘awk -f sleep.awk /var/log/user.log.1’ in your sleep time script.

I’ll have a play to see if I can fix the formatting.

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [January 5, 2016, 12:27am UTC](https://community.wd.com/t/sleep-time/95608/6 "2016-01-05T00:27:05Z")

</div>

It looks like the only formatting problem is with statement above the END { line. You need both log files /var/log/user.log.1 and /var/log/user.log. They also need to be in that order. As the /var/log/user.log.1 is the older log file.

RAC

---

<div class="post-metadata">

**Author:** ![dubie](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/dubie/32/37634_2.png) [@dubie](https://community.wd.com/u/dubie)\
**Post date:** [February 26, 2016, 3:30pm UTC](https://community.wd.com/t/sleep-time/95608/7 "2016-02-26T15:30:36Z")

</div>

I followed the instructions but get this error message when I give the command “sh sleeptime.sh”  
sleeptime.sh: line 1: /nfs/Public/sleep.awk: Permission denied

The sleep.awk and sleeptime.sh are both in the nfs/Public directory

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [February 26, 2016, 4:53pm UTC](https://community.wd.com/t/sleep-time/95608/8 "2016-02-26T16:53:24Z")

</div>

You need to do the following:  
chmod 775 sleep.awk

RAC

---

<div class="post-metadata">

**Author:** ![dubie](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/dubie/32/37634_2.png) [@dubie](https://community.wd.com/u/dubie)\
**Post date:** [February 26, 2016, 5:48pm UTC](https://community.wd.com/t/sleep-time/95608/9 "2016-02-26T17:48:51Z")

</div>

Ok I did the chmod 775 command. Now I get the following result:

Total Sleep Time: 0:00:00  
date: invalid date '//Dec ’  
Start  
date: invalid date '//2016 ’  
End //2016  
Total Up Time: 0:00:00

I guess there is something wrong with the script. I’ve double-checked it against the text in the first post above and it appears OK to me.

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [February 26, 2016, 7:46pm UTC](https://community.wd.com/t/sleep-time/95608/10 "2016-02-26T19:46:07Z")

</div>

The only thing I see is that the one printf statement is split across two lines.

RAC

---

<div class="post-metadata">

**Author:** ![dubie](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/dubie/32/37634_2.png) [@dubie](https://community.wd.com/u/dubie)\
**Post date:** [February 26, 2016, 7:57pm UTC](https://community.wd.com/t/sleep-time/95608/11 "2016-02-26T19:57:45Z")

</div>

just to confirm this is all one line

“printf “%2s %2s %8s %8s %5d %2d:%02d:%02d\n”,substr($1,6,2),substr($1,9,2) ,substr($11,0,9),substr($1,12,8),$8 ,hh1,mm1,ss1}}”

And the last line is  
}’

Is that right?

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [February 26, 2016, 11:03pm UTC](https://community.wd.com/t/sleep-time/95608/12 "2016-02-26T23:03:01Z")

</div>

Yes.

RAC

---

<div class="post-metadata">

**Author:** ![thebadking](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@thebadking](https://community.wd.com/u/thebadking)\
**Post date:** [January 24, 2020, 8:59am UTC](https://community.wd.com/t/sleep-time/95608/13 "2020-01-24T08:59:35Z")

</div>

# sh /mnt/HD/HD\_a2/Public/sleeptime.sh

Total Sleep Time: 0:00:00  
date: invalid date ‘’  
Start  
End 01/23/2020 15:16:31  
Total Up Time: 0:00:01

-rw-r–r-- 1 root root 2 Jan 24 00:48 user.log.1  
-rw-r–r-- 1 root root 2974 Jan 23 15:16 user.log

-rwxrwxrwx 1 root root 64 Jan 23 09:28 sleeptime.sh  
-rwxr-xr-x 1 root root 842 Jan 23 09:26 sleep.awk

the script is not updating, am I missing something?

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [January 24, 2020, 2:52pm UTC](https://community.wd.com/t/sleep-time/95608/14 "2020-01-24T14:52:50Z")

</div>

It has been a couple of years since I’ve worked with these scripts. I think that you have a Gen2 MyCloud.  
I think you are running the Gen1 sleep scripts.

---

<div class="post-metadata">

**Author:** ![thebadking](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@thebadking](https://community.wd.com/u/thebadking)\
**Post date:** [January 24, 2020, 3:24pm UTC](https://community.wd.com/t/sleep-time/95608/15 "2020-01-24T15:24:49Z")

</div>

What is the difference in the script? Do you know?

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [January 24, 2020, 4:41pm UTC](https://community.wd.com/t/sleep-time/95608/16 "2020-01-24T16:41:31Z")

</div>

It is not a difference in the script. The gen1 writes an entry in the log everytime it goes to sleep or wakes up. The Gen2 does not write anything to the log.

---

<div class="post-metadata">

**Author:** ![thebadking](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@thebadking](https://community.wd.com/u/thebadking)\
**Post date:** [January 24, 2020, 11:43pm UTC](https://community.wd.com/t/sleep-time/95608/17 "2020-01-24T23:43:20Z")

</div>

I made a nice script for the latest firmware on Gen2  
to enable app installation  
but I would like to have the logs for sleep time

---

<div class="post-metadata">

**Author:** ![rac8006](https://sea2.discourse-cdn.com/wd/user_avatar/community.wd.com/rac8006/32/34022_2.png) [@rac8006](https://community.wd.com/u/rac8006)\
**Post date:** [January 25, 2020, 3:55am UTC](https://community.wd.com/t/sleep-time/95608/18 "2020-01-25T03:55:51Z")

</div>

As I said the Gen2 does not log sleep time.
