一、需要将一大段IP列表中提取出来,用一个列表的形式展示出来。我们可以如下:
1
2
3
4
|
#vim中将空格转换为回车符号 :%s/\s/\r/g #将空格为首的行清理 :%s/^\s //g |
二、得到列表后,我们可以写一个简单的shell脚本,通过http的方式去获取offline.lst的IP,然后进行自动清理了。如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#!/bin/sh for offip in `curl http: //IP/offline .lst 2> /dev/null ` do #获取网卡设备 netcard=`ip addr| grep brd| grep -vE '(loopback|ether|sit)' | grep -w ${offip}| awk '{print $(NF)}' ` if [ $netcard ]; then echo "$offip $netcard you will down it" read "test" ifsure #备份配置文件 if [ ! -f /etc/rc . local ` date +%F` ]; then cp /etc/rc . local /etc/rc . local ` date +%F` fi #确认可以执行后执行操作 ifconfig $netcard down sed -i "/${offip}/d" /etc/rc . local fi done |