7 月 012016
 

使用脚本定时获取接口动态IP并处理保存

[root@localhost tmp]# cat listip.sh
#
#!/bin/bash

# run @ every 3 hour

cd /tmp/
#执行ping获取花生壳服务所返回的接口IP地址
/bin/ping ddns.domain.com -c 1 |grep 'time=' |awk {'print $4'} > listip.tmp
#处理IP地址后面的:符号
newip=$(sed -e 's/.$//' listip.tmp)
#将处理过的IP存入按日生成临时文件
echo $newip >> ip.`date +%y%m%d`.tmp

exit 0;
[root@localhost tmp]# cat getip.sh
#
#!/bin/bash

# run @ everyday 23:50

cd /tmp/
#对按日生成临时文件中的IP地址进行排序并去除重复行导入按日保存文件
sort -k2n ip.`date +%y%m%d`.tmp |uniq > ip.`date +%y%m%d`.txt

rm -f ip.`date +%y%m%d`.tmp

exit 0;
[root@localhost tmp]#

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)