亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: 如何統(tǒng)計文本中字符串出現(xiàn)的數(shù)量 [打印本頁]

作者: 338378WN8    時間: 2015-07-03 10:20
標題: 如何統(tǒng)計文本中字符串出現(xiàn)的數(shù)量
一臺服務器,一直報打開文件數(shù)過多。
想寫個腳本用lsof命令查找是那個用戶哪個進程打開的文件數(shù)最多。
比如lsof出現(xiàn)的信息如下
COMMAND     PID      USER   FD      TYPE             DEVICE     SIZE       NODE NAME
init          1      root  cwd       DIR                8,2     4096          2 /
init          1      root  rtd       DIR                8,2     4096          2 /
init          1      root  txt       REG                8,2    43496     415811 /sbin/init
init          1      root  mem       REG                8,2   139416     575728 /lib64/ld-2.5.so
init          1      root  mem       REG                8,2  1717800     575729 /lib64/libc-2.5.so
init          1      root  mem       REG                8,2    23360     575731 /lib64/libdl-2.5.so
init          1      root  mem       REG                8,2   247496     575745 /lib64/libsepol.so.1
init          1      root  mem       REG                8,2    95464     575746 /lib64/libselinux.so.1
init          1      root   10u     FIFO               0,17                2769 /dev/initctl
migration     2      root  cwd       DIR                8,2     4096          2 /
migration     2      root  rtd       DIR                8,2     4096          2 /
migration     2      root  txt   unknown                                        /proc/2/exe
ksoftirqd     3      root  cwd       DIR                8,2     4096          2 /
ksoftirqd     3      root  rtd       DIR                8,2     4096          2 /
ksoftirqd     3      root  txt   unknown                                        /proc/3/exe
migration     4      root  cwd       DIR                8,2     4096          2 /
migration     4      root  rtd       DIR                8,2     4096          2 /
migration     4      root  txt   unknown                                        /proc/4/exe
ksoftirqd     5      root  cwd       DIR                8,2     4096          2 /
ksoftirqd     5      root  rtd       DIR                8,2     4096          2 /
ksoftirqd     5      root  txt   unknown                                        /proc/5/exe
events/0      6      root  cwd       DIR                8,2     4096          2 /
events/0      6      root  rtd       DIR                8,2     4096          2 /
events/0      6      root  txt   unknown                                        /proc/6/exe
events/1      7      root  cwd       DIR                8,2     4096          2 /
events/1      7      root  rtd       DIR                8,2     4096          2 /

那有什么方法可以自動計算每個進程打開了多少文件,并根據(jù)打開文件的數(shù)量自動排序?
作者: 338378WN8    時間: 2015-07-03 10:32
自己能想得到的是用 lsof |awk '{print $2}'|uniq -c|sort -g
作者: dn833    時間: 2015-07-03 11:16
  1. awk '{a[$2]++}END{for(i in a)print i,a[i]|"sort -n"}'
復制代碼

作者: hjfeng1988    時間: 2015-07-03 11:38
統(tǒng)計進程:
  1. awk 'NR>1{a[$1]++}END{for(i in a)print i,a[i]}' file | sort -n -k2,2
復制代碼
統(tǒng)計用戶:
  1. awk 'NR>1{a[$3]++}END{for(i in a)print i,a[i]}' file | sort -n -k2,2
復制代碼

作者: haooooaaa    時間: 2015-07-03 13:28
本帖最后由 haooooaaa 于 2015-07-03 13:58 編輯

回復 1# 338378WN8
  1. [root@cAdmin 456]# lsof | awk 'function f(d){for(i in d){printf "%-18s %-10s\n",i,d[i] | "sort -k2nr"};close("sort -k2nr");print "=================="}NR>1&&$5!~/unknown/{p[$1]++;u[$3]++}END{f(u);f(p)}'
  2. root               729      
  3. postfix            92        
  4. haldaemon          53        
  5. dbus               25        
  6. rpc                24        
  7. rpcuser            24        
  8. ==================
  9. master             126      
  10. sshd               96        
  11. cupsd              57        
  12. mingetty           48        
  13. pickup             46        
  14. qmgr               46        
  15. udevd              46        
  16. hald               37        
  17. automount          36        
  18. hald-addo          35        
  19. lsof               26        
  20. dbus-daem          25        
  21. rpcbind            24  
復制代碼

作者: 338378WN8    時間: 2015-07-03 14:17
回復 4# hjfeng1988

嗯,這個好像可以的


   
作者: 338378WN8    時間: 2015-07-03 14:18
回復 5# haooooaaa
高手啊,sed我還看得懂,awk基本就抓瞎了。


   
作者: Herowinter    時間: 2015-07-03 15:55
回復 7# 338378WN8


    理論上來說, awk比較好懂吧,比較接近高級語言的語法.




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2