hdd spin down - startup script

Post new topic   Reply to topic    DD-WRT Forum Index -> Marvell MVEBU based Hardware (WRT1900AC etc.)
Author Message
thekk
DD-WRT User


Joined: 09 May 2016
Posts: 58

PostPosted: Wed Oct 05, 2016 9:52    Post subject: hdd spin down - startup script Reply with quote
Hi Folks, i tried to give my networkstorage some breaks and failed at the cron setup.

I use sdparm to spin down because hdparm doesnt recognize my hdd.
I wrote a little shell script to check the activity on the hdd and do a spin down after 20 minutes without activity.
This works well.
But now, i want to start the script automatical with cron, using this command:

@reboot /bin/sh /jffs/etc/hdd.sh 20 &

The script runs and i dont get any errors in log but the hdd doenst spin down and there is no output in log.
I save the date if there is a spin down.

whats wrong with cron?


Last edited by thekk on Wed Oct 05, 2016 22:01; edited 1 time in total
Sponsor
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Wed Oct 05, 2016 10:34    Post subject: Re: cron @reboot problem Reply with quote
thekk wrote:
Hi Folks, i tried to give my networkstorage some breaks and failed at the cron setup.

I use sdparm to spin down because hdparm doesnt recognize my hdd.
I wrote a little shell script to check the activity on the hdd and do a spin down after 20 minutes without activity.
This works well.
But now, i want to start the script automatical with cron, using this command:

@reboot /bin/sh /jffs/etc/hdd.sh 20 &

The script runs and i dont get any errors in log but the hdd doenst spin down and there is no output in log.
I save the date if there is a spin down.

whats wrong with cron?
your formatting, try:

*/20 * * * * root /jffs/etc/hdd.sh

as well, you can just add the cron job in the gui next to the cron job section. it will be stored in nvram and will persist over reboots.

https://www.dd-wrt.com/wiki/index.php/CRON
thekk
DD-WRT User


Joined: 09 May 2016
Posts: 58

PostPosted: Wed Oct 05, 2016 10:53    Post subject: Reply with quote
Thanks for your answer but i guess you don't read my text complete.
*/20 * * * * root /jffs/etc/hdd.sh
This runs the script every 20 minutes, thats not what i want.
The script is a infinity cycle that should started one time and run in backround, see @reboot and &.

For a startup command, its needed to invoke the shell /bin/sh because stdout and stderr pipes will not work without.

Iam unsure about the login but if i add root after the @reboot, the script dont start.

Your example work for me. I know this because i have 2 ohter job in this format.
My problem is the @reboot condition.
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Wed Oct 05, 2016 12:25    Post subject: Reply with quote
thekk wrote:
Thanks for your answer but i guess you don't read my text complete.
*/20 * * * * root /jffs/etc/hdd.sh
This runs the script every 20 minutes, thats not what i want.
The script is a infinity cycle that should started one time and run in backround, see @reboot and &.

For a startup command, its needed to invoke the shell /bin/sh because stdout and stderr pipes will not work without.

Iam unsure about the login but if i add root after the @reboot, the script dont start.

Your example work for me. I know this because i have 2 ohter job in this format.
My problem is the @reboot condition.


Okay, so maybe write a script that instead of invoking through cron, starts with *.startup

https://www.dd-wrt.com/wiki/index.php/Startup_Scripts


You could simply write a script (qualifying it with /bin/sh) like follows:


#!/bin/sh
/jffs/etc/hdd.sh &


That would be all you need. So when the router starts, it executes the hdd.startup (or whatever you name it) and executes your script in the background.


Last edited by cybrnook on Wed Oct 05, 2016 12:29; edited 2 times in total
thekk
DD-WRT User


Joined: 09 May 2016
Posts: 58

PostPosted: Wed Oct 05, 2016 12:29    Post subject: Reply with quote
uuhh, i dont stumled upon this feature for startup scripts. Thanks for this information.
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Wed Oct 05, 2016 12:37    Post subject: Reply with quote
thekk wrote:
uuhh, i dont stumled upon this feature for startup scripts. Thanks for this information.


They work rather well! Just keep in mind that your script will likely get executed a few times during the boot process if you use a .startup. So you might want to add some simple check conditions to it so that only one instance is running.

Something like:

#!/bin/sh

if
ps | grep hdd.sh
then
exit 0
else
/jffs/etc/hdd.sh &
fi
thekk
DD-WRT User


Joined: 09 May 2016
Posts: 58

PostPosted: Wed Oct 05, 2016 18:09    Post subject: Reply with quote
Thanks for this good purposal, maybe i will add this.

Finally i tested the startup script function in the gui and get the same result as with cron.

So i add some debug information and tested ist.
The problem was the date function in startup state of the router.
I just check the time in seconds, save it in a variable and compare it late with the current time. But in startup state, the date is epoch and ofc i forgot this.
So i never reach the condition to spin down.
Added sleep 30 for this.

Thanks for holding my hand with this stupid bug.
The script is attached for interested, syntax are in the header.


Last edited by thekk on Wed Oct 05, 2016 21:13; edited 1 time in total
cybrnook
DD-WRT User


Joined: 08 Jan 2014
Posts: 279

PostPosted: Wed Oct 05, 2016 18:37    Post subject: Reply with quote
thekk wrote:
Thanks for this good purposal, maybe i will add this.

Finally i tested the startup script function in the gui and get the same result as with cron.

So i add some debug information and tested ist.
The problem was the date function in startup state of the router.
I just check the time in seconds, save it in a variable and compare it late with the current time. But in startup state, the date is epoch and ofc i forgot this.
So i never reach the condition to spin down.
Added sleep 30 for this.

Thanks for holding my hand with this stupid bug.
The script is attached for interested, syntax are in the header.


I was going to suggest that Smile in my own custom scripts I also have a few sleep commands to let the system settle down Smile

Good Job!
zmatek
DD-WRT Novice


Joined: 06 Dec 2016
Posts: 3

PostPosted: Tue Dec 06, 2016 20:35    Post subject: Spin down script Reply with quote
Hi thekk,

I am really interested,but I cannot find your script attached. I need to firgure out the same,but for real linux noob its difficult to manage in dd wrt:(
In debian was not so difficult to download and install hdparm.
So in dd wrt I should use that "Command" dialog box to submit a command? Or just better to connect ssh terminal?

Any advice will help a lot. Thank you in advance.
Kind regards zma
thekk
DD-WRT User


Joined: 09 May 2016
Posts: 58

PostPosted: Wed Dec 07, 2016 9:51    Post subject: Reply with quote
zmatek wrote:
Hi thekk,

I am really interested,but I cannot find your script attached. I need to firgure out the same,but for real linux noob its difficult to manage in dd wrt:(
In debian was not so difficult to download and install hdparm.
So in dd wrt I should use that "Command" dialog box to submit a command? Or just better to connect ssh terminal?

Any advice will help a lot. Thank you in advance.
Kind regards zma


The script is attached there http://www.dd-wrt.com/phpBB2/viewtopic.php?p=1049540#1049540
Just hit on "Download".

You dont need my script for hdparm because hdparm has its own timing function to spin down after a while. The script is just for sdparm.

Pls do research on google for hdparm syntax and functionality.

For installing hdparm you have to activate jffs on an separate usb drive and install optware there.
Maybe you will find this helpfull:
https://www.dd-wrt.com/wiki/index.php/Optware
zmatek
DD-WRT Novice


Joined: 06 Dec 2016
Posts: 3

PostPosted: Wed Dec 07, 2016 21:55    Post subject: USB drive spin-down setting Reply with quote
Evening Thekk,

thanks a lot for your feedback!
I am maybe to old for that and really depressed. I believe you can help me to find way out:(

So this is the story..I wanted decent router with NAS, so I bought R7000 Nighthawk. SATA drives were connected and everything worked fine with stock firmware...include spin down of the drives... unluckily netgear has some bug in their firmware, and usb drives were loosing samba config during system init. when router reboot or power cycle.
One of them always disconnected. I had to mount again via web gui.... annoying.
So I tried DD WRT, and was able to easily setup wifi, guest wifi, usb nas samba dlna and was thinking wow thats great OS and awesome web gui!

Until I realised that drives are still active, not spining down at all and thats not good I think...

I googled a lot, and of course started with dd wrt wiki, where is quite wide info about USB storage, and is stated in relation with spin down:

"sudo apt-get install sdparm
sudo sdparm -a /dev/sd?"

and thats place where the pain has began:!

first command "sudo apt-get install sdparm"
bump "-sh: sudo: not found"

ah.. something has changed since times I was playing with debian in childhood. Googling several hours, I found something about OpenWRT and Optware, no other ideas lets give it try:

Enabled JFFS2 flash memory in web gui because I do not wants to use external flash. Then putty into ssh shell:

"mkdir /jffs/opt
mount --bind /jffs/opt /opt
bootstrap"

and opkg was installed, now I was able to simply install hdparm with:

"opkg install hdparm"

again short happiness,

until first command "hdparm -S 245 /dev/sda2"
bump "hdparm: ioctl 0x31f failed: Invalid argument"

oh.. whats wrong.. googling quite a lot and seems like hdparm does not work well via USB.

so lets try sdparm, at first install with similar command "opkg install sdparm"
bump "unknown package 'sdparm' "

am I really missing something?
I just wants to enable spin down of my drives.

I just would like to define spin down time for those USB drives and to make that setting persisten against reboot or power cycle...possibly using nvram or internal flash.

I was really googling a lot, but found none tutorial how to spin down in dd wrt for noobs:(

For me there is only wish to be able enable and control spin down interval for USB drives, could you give me and advice? is script kind of solution? if yes, how to install sdparm?

Thank you in advance for any clue and helpfulness!

Kind regards zma
PS: sorry for boring story... but it is difficult to describe for windows ppl:(
thekk
DD-WRT User


Joined: 09 May 2016
Posts: 58

PostPosted: Thu Dec 15, 2016 10:22    Post subject: Re: USB drive spin-down setting Reply with quote
zmatek wrote:

until first command "hdparm -S 245 /dev/sda2"
bump "hdparm: ioctl 0x31f failed: Invalid argument"


You should use more time in reading then in texting.
"Invalid argument" says all what you need.
sda2 is an partition, not the device.

Pls refer on a tutorial for using hdparm and read the man page.

If you search on google you will find massive items on using hdparm and sdparm, how to test if your hdd works with it and how to install it.

Maybe you will start reading in DD-WRT wiki. There is also an article about usb-storage where is described how to install sdparm.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Marvell MVEBU based Hardware (WRT1900AC etc.) All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum