07月 4th, 2008 xiao H Posted in shell, 系统管理 |
下面是我平常用的一些bash shell 组合,方便我的日常管理。
清除所有arp 缓存
arp -n|awk '/^[1-9]/ {print "arp -d "$1}'|sh
显示打开连接数前10个机子的IP 和连接数
cat /proc/net/ip_conntrack | cut -d ' ' -f 10 | cut -d '=' -f 2 | sort | uniq -c | sort -nr | head -n 10
绑定已知机子的arp 地址
cat /proc/net/arp | awk '{print $1 " " $4}' |sort -t. -n +3 -4 > /etc/ethers
批量重命名
ls dirname | awk '{printf"mv %s file_%06d\n",$0,i++}' | sh
Per脚本实现eth0挂起后自动重启
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/usr/bin/perl -w $fail_count = 0; $cmd_result = ''; $cmd_result = `ping -w 4 61.130.107.193 |grep packet`; if ($cmd_result =~ /100% packet loss/) { $fail_count++; if ($fail_count > 5) { `ifdown eth0`; `ifup eth0`; } else { $fail_count = 0; } } |
自动从apnic记录中分离出网通,电信IP 段
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #!/bin/sh FILE=/root/ip.txt rm -f $FILE wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest -O $FILE grep 'apnic|CN|ipv4|' $FILE | cut -f 4,5 -d'|'|sed -e 's/|/ /g' | while read ip cnt do echo $ip:$cnt mask=$(cat < < EOF | bc | tail -1 pow=32; define log2(x) { if (x<=1) return (pow); pow--; return(log2(x/2)); } log2($cnt) EOF) echo $ip/$mask>> cn.net NETNAME=`whois $ip@whois.apnic.net | sed -e '/./{H;$!d;}' -e 'x;/netnum/!d' |grep ^netname | sed -e 's/.*: \(.*\)/\1/g' | sed -e 's/-.*//g'` case $NETNAME in CNC) echo $ip/$mask >> CNCGROUP ;; CHINANET|CNCGROUP) echo $ip/$mask >> $NETNAME ;; CHINANET|CNCGROUP) echo $ip/$mask >> $NETNAME ;; CHINATELECOM) echo $ip/$mask >> CHINANET ;; *) echo $ip/$mask >> OTHER ;; esac done |
标签:Bash
本站原创作品采用知识共享署名-相同方式共享 3.0 许可协议进行许可。
转载请注明 作者:xiao H,出处:linuxbyte.org ,原始链接:我常用的小shell
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
我来说两句