Skip to content

Instantly share code, notes, and snippets.

@iansheridan
Created December 16, 2011 16:30
Show Gist options
  • Save iansheridan/1486730 to your computer and use it in GitHub Desktop.
Save iansheridan/1486730 to your computer and use it in GitHub Desktop.
Watcher script for Ruby
#!/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