Advertisement
Guest User

Untitled

a guest
Jan 24th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.57 KB | None | 0 0
  1. #!/usr/bin/ruby
  2. # ./script on -- turn restrictions on
  3. # ./script off -- turn restrictions off
  4.  
  5. @hosts = '/etc/hosts'
  6. @time_eaters = [
  7.   'habrahabr.ru',
  8.   'pink.habrahabr.ru',
  9. ];
  10.  
  11. def deny_time_eaters
  12.   File.open(@hosts, 'a') do |f|
  13.     f.puts( @time_eaters.map {|s| "127.0.0.1    %-30s # TIME EATER" % s} )
  14.   end
  15. end
  16.  
  17. def allow_time_eaters
  18.   system "sed -i.bak '/TIME EATER/ d' #{@hosts}"
  19. end
  20.  
  21.  
  22. action = ARGV.shift || 'on'
  23. case action
  24.   when 'on' then  deny_time_eaters
  25.   when 'off' then allow_time_eaters
  26.   else
  27.     raise "Unkwnown action '#{action}'"
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement