Created
August 23, 2015 06:17
-
-
Save aont/ea76eed88964e4530d70 to your computer and use it in GitHub Desktop.
Check WOL and caffeinate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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