Sleep time

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

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

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

collums are month day enter sleep time wake up time total sleep time hr:mm:sec.  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 }’

1 Like

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. In any case be careful while modifying system files.

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

RAC

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

1 Like

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.

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

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

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

RAC

1 Like

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.

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

RAC

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?

Yes.

RAC

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?

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.

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

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.

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

As I said the Gen2 does not log sleep time.