Preventing etxternal usb 3 hard disk from going to sleep
The above problem has been annoying me for a while. Its preventing me to do a copy of my main backup harddisk.
I have two approaches underway atm. One is
sudo sdparm --clear STANDBY -6 /dev/sde
the other is a little python script that will keep the disk busy in a given interval.
#!/usr/bin/python import os, sys, random,time if len(sys.argv) != 3: print 'usage:\n %s path interval' % sys.argv sys.exit() path = sys.argv interval = sys.argv prefix = 'prevent_standby_' while 1: #delete old ones oldnames = [n for n in os.listdir(path) if n.startswith(prefix)] for name in oldnames: oldpath = os.path.join(path,name) os.unlink(oldpath) print 'deleted '+oldpath print #write new suffix = random.randint(1000000,9999999) newname = os.path.join(path,prefix+str(suffix)) content = 'foo %s' % random.randint(1000000,9999999) fh = open(newname,'w') fh.write(content) fh.close() print 'wrote '+newname os.system('sync') time.sleep(int(interval))
Lets wait to see which one actually works
Ok, at least one combination does work: the script above and disabling power management by doing:
sudo hdparm -B 255 /dev/sde
On the one side this shows the harddisk to be somewhat unusable - but just doing a copy of another hd, and storing this hd somewhere offline, its good enough.