Created
December 16, 2011 16:30
-
-
Save iansheridan/1486730 to your computer and use it in GitHub Desktop.
Watcher script for Ruby
This file contains 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 -w | |
# Ruby implementation of the GNU watch command line utility for Mac OS X. | |
# Written by: Ian Sheridan. December 2011. | |
# Email: ian.sheridan[@]gmail.com | |
if ARGV.length == 0 | |
puts 'Syntax: watch.rb <unix commands>' | |
puts 'If command contains parameters, make sure to enclose them with single quotes' | |
exit | |
else | |
command = ARGV.shift | |
end | |
print "'Ctrl + C': to end this program.......\n" | |
# equivalent to watch -n 2 command | |
while 1 do | |
pipe = IO.popen(command, 'r') | |
puts pipe.readlines.join | |
sleep(2) | |
Process.kill("KILL", pipe.pid) | |
pipe.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment