如何删除ssh映射中的重复脚本?

如何删除ssh映射中的重复脚本?用python?awk或sed?

只要实现就可以

[root@localhost company]# cat nat.cfg
29003 192.168.5.170:29003
29003 192.168.5.170:29003
29093 192.168.5.169:29093
[root@localhost company]# for i in `cat nat.cfg |awk '{print $2}'`;do grep $i nat.cfg;grep $i nat.cfg|wc -l;done
29003 192.168.5.170:29003
29003 192.168.5.170:29003
2
29003 192.168.5.170:29003
29003 192.168.5.170:29003
2
29093 192.168.5.169:29093
1

-------------------------------------------------

[root@localhost company]# cat chuli.py
import os
cmd = "for i in `cat nat.cfg |awk '{print $2}'`;do grep $i nat.cfg|wc -l;done"
num_cmd = os.popen(cmd)
while True:
    i = num_cmd.readline().strip()
    if i == '':
        break
    else:
        if i >1:
            print 'need delete %s'%i
        else:
            pass

[root@localhost company]# python chuli.py
need delete 2
need delete 2
need delete 1

 

posted @ 2015-07-05 23:30  arun_yh  阅读(341)  评论(0编辑  收藏  举报