- 时间:2022-12-27 20:04 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:Shell脚本自动更新hosts实现免翻墙访问google
上次给大家发了一个[url=http://www.1sucai.cn/article/61052.htm]python更新google hosts的脚本[/url],今天看到有人发出了一句用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