当前位置: 移动技术网 > 网络运营>服务器>Linux > Shell脚本自动更新hosts实现免翻墙访问google

Shell脚本自动更新hosts实现免翻墙访问google

2018年03月22日  | 移动技术网网络运营  | 我要评论

上次给大家发了一个,今天看到有人发出了一句用shell来获取google hosts的脚本,我就拿来稍微简单加工了下,下面给大家shell版的更新google hosts的脚本。

脚本内容:

复制代码 代码如下:

cat google_update.sh
#!/bin/bash
data=`date +%y%m%d%h%m`
curl http://www.360kb.com/kb/2_122.html 2>/dev/null | sed -n '/#google-hosts-2015/,/#google-hosts-2015-end/{s/ //g; s/<.*>//g; p}' >/tmp/hosts
cp /etc/hosts /etc/hosts_$data.bak
mv /tmp/hosts /etc/hosts
cat>>/etc/hosts<<eof
127.0.0.1        testbak localhost.localdomain localhost
::1        localhost6.localdomain6 localhost6
eof

也一样丢到crontab里,每隔3天更新一次
复制代码 代码如下:

0 0 */3 * * /bin/sh /root/soft_shell/google_update.sh

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网