用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
网友评论