Skip to content

Instantly share code, notes, and snippets.

@aont
Created August 23, 2015 06:17
Show Gist options
  • Select an option

  • Save aont/ea76eed88964e4530d70 to your computer and use it in GitHub Desktop.

Select an option

Save aont/ea76eed88964e4530d70 to your computer and use it in GitHub Desktop.
Check WOL and caffeinate
#!/usr/bin/ruby
# coding: utf-8
filepath="/var/log/system.log"
fpointer = 0
f = open(filepath)
f.seek(0, IO::SEEK_END)
fpointer = f.pos
while true
l = f.gets
fpointer = f.pos
if l
# puts l
if /Wake reason: GIGE/ =~ l
puts "[ruby] GIGE"
system("caffeinate -u sh -c \"\"")
break
elsif /full wake/ =~ l
puts "[ruby] full wake"
break
end
else
f.close unless f.closed?
closetime = File.mtime(filepath)
while (File.mtime(filepath) == closetime)
sleep 1
end
f = open(filepath)
f.seek(fpointer, IO::SEEK_SET)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment