Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple little script to keep my external drive spinning as it likes to go to sleep... lots...
#!/usr/bin/env ruby
#
# Keep the external drive spining!
#
require 'fileutils'
# set the name of the file to write
FILE = '/Volumes/Drive_Name/.stayawake'
# add a welcome message, that strange bit of text clears the screen
# SEE: http://stackoverflow.com/questions/10261359/ruby-clear-screen
puts <<WELCOME
\e[2J\e[f
*********************
** Drive Spinner ****
*********************
WELCOME
# keep touching a file on the drive every 10 minutes
1.upto Float::INFINITY do |i|
if File.writable? FILE
puts "Keeping the drive spinning... forever...\n\r" if i.eql? 1
# touch file
FileUtils.touch FILE
# sleep for 10 minutes
sleep 600
else
# break out of the loop
puts "File looks like it's not writeable, is the drive mounted?\n\r"
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment