ruby實現(xiàn)修改ubuntu下的hosts
更新時間:2015年06月04日 09:47:43 投稿:hebedich
本文給大家分享的是通過ruby獲取github上的hosts文件內(nèi)容,修改到本地Ubuntu中,十分的實用,具體你懂得,有需要的小伙伴可以參考下。
在Windows下面,我們修改hosts文件都知道在哪里,但是在ubuntu系統(tǒng)中呢,還有其它的系統(tǒng),比如安卓手機,或許就沒那么多的小軟件可供你簡單的修改了,我們自己來寫個吧
#!/usr/bin/ruby
#coding=utf-8
require 'open-uri'
url= "http ://raw.github usercontent.com/vokins/simpleu/master/hosts"
begin
open("/etc/hosts","w") do |x|
x.write open(url).read
end
rescue Errno::EACCES
puts "Need root? "
exec "sudo ruby " + $0 + ARGV.join(' ')
end
puts "Write hosts success!"
以上所述就是本文的全部內(nèi)容了,希望大家能喜歡
相關文章
Ruby實現(xiàn)命令行中查看函數(shù)源碼的方法
這篇文章主要介紹了Ruby實現(xiàn)命令行中查看函數(shù)源碼的方法,,需要的朋友可以參考下2014-07-07
在Ruby on Rails上使用Redis Store的方法
這篇文章主要介紹了在Ruby on Rails上使用Redis Store的方法,是Ruby程序和Redis數(shù)據(jù)庫結(jié)合的有效途徑,需要的朋友可以參考下2015-06-06

