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

上次给大家发了一个python更新google hosts的脚本,今天看到有人发出了一句用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