2:00am, finals week, what would be a good use of my time? Oh, yeah, how about writing a little bash script to keep my external hard drive from constantly spinning down? Observe:
#!/bin/bash while [ true ] do touch /media/BigEx/.keephdactive sleep 4m done
Wow, right?
Yeah, it’s been kind of bothering me for months, nothing on the internet anywhere had an easy way to do this. And then, after 5-ten minutes of googling in vain all of a sudden I thought to myself: “Hey man, you’re supposed to be a computer scientist, (tbd) can’t you do something about this?” And so, in less time than several failed google searches, I had this.
If you’re on linux and you want to get this running, copy & paste the following into your terminal. It will open up your text editor, inside of which you should change the “BigEx” to the name of your external hard drive. (What it shows up as in the menus and such.) These commands will just put it in your home folder, at the end there’s a command to move it out of there, if you don’t know how.
If you’re in GNOME (eg Ubuntu):
wget http://svn.quodlibetor.com/pubsh/bash/hdactive.sh && gedit hdactive.sh && chmod +rx hdactive.sh
If you’re in KDE (eg Kubuntu, Fedora 9):
wget http://svn.quodlibetor.com/pubsh/bash/hdactive.sh && kate hdactive.sh && chmod +rx hdactive.sh
The only difference between them is a different text editor. (The “&&”s are just ways to join multiple commands together in one line, I did it so that you won’t have to copy/paste 3 times just to get a little hack working :)
Last thing to do then is run it:
./hdactive.sh &
should do it. (The “&” just means “run this process in the background.”)
If you’re in GNOME and you want this file to run every time you start your system, first it’s probably a good idea to put it in your /usr/bin directory:
sudo mv hdactive.sh /usr/bin/
And then you’ll want to add it to your startup session, which is something I don’t know a command for, or how to do it in KDE, so menus time: “System -> Preferences -> Sessions” select “+ add” from the right side, for the name put “HDactive” (or whatever) for the command put “hdactive.sh” (no quotes) and for comment put “oh man quodlibetor’s friggin’ sweet.”
That last part is essential for the proper working of the code :)
OK, it’s now officially been an hour and fifteen minutes since I thought “damn I wish my hard drive would stay on.” On the one hand, that’s way too long, on the other hand, my hard drive has stayed on :)
p.s. I know that there are at least a couple things to do to make this work better (eg accept parameters instead of making people change the code by hand) this works for me, and it’s also damn near my first working bash script ever, so I’ll change it as I have time. I promise that the link will always work though, and if I change it enough that these instructions don’t apply any more I’ll put comments inside it so anybody trying to edit a newer version will see that something’s weird and what to do about it. You can consider it currently licensed under the WTFPL, so do wtf you want to with it :)
[edited a whole bunch of times to get some basic code formatting and syntax highlighting working, since this is my first post with actual code]

{ 1 } Comments
Hey there, I’m an editor working on PC (windows Vista).
Just bought a 1 TB external HD to edit with and I need it to not spin down (sleep)
any chance of this script working for me?
How might I go about it (I’m not a programmer, but I know my way around a PC)
Cheers for any help
-Ferand
Post a Comment