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

Chinaunix

標(biāo)題: 求助 編寫一個(gè)shell腳本 [打印本頁(yè)]

作者: qinghan1125    時(shí)間: 2010-05-14 21:04
標(biāo)題: 求助 編寫一個(gè)shell腳本
一個(gè)文件包括多次ps aux的執(zhí)行結(jié)果,我想對(duì)每次的ps aux計(jì)算其%cpu的和(注意:其中每次ps aux得到的行數(shù)不一定一樣,比如第一次ps aux結(jié)果有10行,第二次ps aux有8行)

bj-djt-win-scp1b scu/bin> ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       145  0.1  0.0      0     0 ?        S    May08  10:34 [pdflush]
root      7773  0.2  0.0   9008  2500 ?        Ss   May08  27:24 /bin/sh /etc/init.d/init.cssd fatal
root      8995  0.4  0.3 473856 28840 ?        Ssl  May08  45:27 /oracle/crs/bin/crsd.bin reboot
oracle   12474  0.2  2.6 233344 217844 ?       SLl  May08  22:04 /oracle/crs/bin/ocssd.bin
scu      29189  0.8  0.6  70716 50404 ?        S    May08  79:50 manager 0
scu      29221  1.0  2.8 1239576 230188 ?      S    May08 100:59 scf 0 1
scu      29222  1.0  2.8 1239512 229856 ?      S    May08 100:42 scf 0 2
scu      29223  1.0  2.8 1239676 229924 ?      S    May08  99:58 scf 0 3
scu      29224  1.0  2.8 1239508 230132 ?      S    May08 100:08 scf 0 4
oracle   29339  0.3  7.7 4302156 631068 ?      Ss   May08  31:46 oracleora11g2 (LOCAL=NO)
oracle   29346  0.3  7.7 4302152 631824 ?      Ss   May08  31:49 oracleora11g2 (LOCAL=NO)
oracle   29353  0.3  7.7 4302104 629432 ?      Ss   May08  31:30 oracleora11g2 (LOCAL=NO)
oracle   29360  0.3  7.7 4302112 626508 ?      Rs   May08  31:42 oracleora11g2 (LOCAL=NO)
root     24151  0.3  0.0   8200  3092 ?        S<L  00:00   2:46 /usr/bin/atop -a -w /var/log/atop/atop_20100514 10
bj-djt-win-scp1b scu/bin> ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       145  0.1  0.0      0     0 ?        S    May08  10:34 [pdflush]
root      7773  0.2  0.0   9008  2500 ?        Ss   May08  27:24 /bin/sh /etc/init.d/init.cssd fatal
root      8995  0.4  0.3 473856 28840 ?        Ssl  May08  45:27 /oracle/crs/bin/crsd.bin reboot
oracle   12474  0.2  2.6 233344 217844 ?       SLl  May08  22:04 /oracle/crs/bin/ocssd.bin
scu      29189  0.8  0.6  70716 50404 ?        S    May08  79:50 manager 0
scu      29221  1.0  2.8 1239576 230188 ?      S    May08 100:59 scf 0 1
scu      29222  1.0  2.8 1239512 229856 ?      S    May08 100:42 scf 0 2
scu      29223  1.0  2.8 1239676 229924 ?      S    May08  99:58 scf 0 3
scu      29224  1.0  2.8 1239508 230132 ?      S    May08 100:08 scf 0 4
oracle   29339  0.3  7.7 4302156 631080 ?      Ss   May08  31:46 oracleora11g2 (LOCAL=NO)
oracle   29346  0.3  7.7 4302152 631828 ?      Ss   May08  31:49 oracleora11g2 (LOCAL=NO)
oracle   29353  0.3  7.7 4302104 629432 ?      Ss   May08  31:30 oracleora11g2 (LOCAL=NO)
oracle   29360  0.3  7.7 4302112 626508 ?      Ss   May08  31:42 oracleora11g2 (LOCAL=NO)
root     24151  0.3  0.0   8200  3092 ?        S<L  00:00   2:46 /usr/bin/atop -a -w /var/log/atop/atop_20100514 10
bj-djt-win-scp1b scu/bin> ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       145  0.1  0.0      0     0 ?        S    May08  10:34 [pdflush]
root      7773  0.2  0.0   9008  2500 ?        Ss   May08  27:24 /bin/sh /etc/init.d/init.cssd fatal
root      8995  0.4  0.3 473856 28840 ?        Ssl  May08  45:27 /oracle/crs/bin/crsd.bin reboot
oracle   12474  0.2  2.6 233344 217844 ?       SLl  May08  22:04 /oracle/crs/bin/ocssd.bin
scu      29189  0.8  0.6  70716 50404 ?        S    May08  79:50 manager 0
scu      29221  1.0  2.8 1239576 230188 ?      S    May08 100:59 scf 0 1
scu      29222  1.0  2.8 1239512 229856 ?      S    May08 100:42 scf 0 2
scu      29223  1.0  2.8 1239676 229924 ?      S    May08  99:58 scf 0 3
scu      29224  1.0  2.8 1239508 230132 ?      S    May08 100:08 scf 0 4
oracle   29339  0.3  7.7 4302156 631080 ?      Ss   May08  31:46 oracleora11g2 (LOCAL=NO)
oracle   29346  0.3  7.7 4302152 631836 ?      Ss   May08  31:49 oracleora11g2 (LOCAL=NO)
oracle   29353  0.3  7.7 4302104 629432 ?      Ss   May08  31:30 oracleora11g2 (LOCAL=NO)
oracle   29360  0.3  7.7 4302112 626508 ?      Ss   May08  31:42 oracleora11g2 (LOCAL=NO)
root     24151  0.3  0.0   8196  3088 ?        S<L  00:00   2:46 /usr/bin/atop -a -w /var/log/atop/atop_20100514 10
bj-djt-win-scp1b scu/bin> ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       145  0.1  0.0      0     0 ?        S    May08  10:34 [pdflush]
root      7773  0.2  0.0   9008  2500 ?        Ss   May08  27:24 /bin/sh /etc/init.d/init.cssd fatal
root      8995  0.4  0.3 473856 28840 ?        Ssl  May08  45:27 /oracle/crs/bin/crsd.bin reboot
oracle   12474  0.2  2.6 233344 217844 ?       SLl  May08  22:04 /oracle/crs/bin/ocssd.bin
scu      29189  0.8  0.6  70716 50404 ?        S    May08  79:50 manager 0
scu      29221  1.0  2.8 1239576 230188 ?      S    May08 101:00 scf 0 1
scu      29222  1.0  2.8 1239512 229856 ?      S    May08 100:42 scf 0 2
scu      29223  1.0  2.8 1239676 229924 ?      S    May08  99:58 scf 0 3
scu      29224  1.0  2.8 1239508 230132 ?      S    May08 100:08 scf 0 4
oracle   29339  0.3  7.7 4302156 631080 ?      Ss   May08  31:47 oracleora11g2 (LOCAL=NO)
oracle   29346  0.3  7.7 4302152 631836 ?      Ss   May08  31:49 oracleora11g2 (LOCAL=NO)
oracle   29353  0.3  7.7 4302104 629432 ?      Ss   May08  31:30 oracleora11g2 (LOCAL=NO)
oracle   29360  0.3  7.7 4302112 626508 ?      Ss   May08  31:42 oracleora11g2 (LOCAL=NO)
root     24151  0.3  0.0   8196  3088 ?        S<L  00:00   2:46 /usr/bin/atop -a -w /var/log/atop/atop_20100514 10
bj-djt-win-scp1b scu/bin> ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       145  0.1  0.0      0     0 ?        S    May08  10:34 [pdflush]
root      7773  0.2  0.0   9008  2500 ?        Ss   May08  27:24 /bin/sh /etc/init.d/init.cssd fatal
root      8995  0.4  0.3 473856 28840 ?        Ssl  May08  45:27 /oracle/crs/bin/crsd.bin reboot
oracle   12474  0.2  2.6 233344 217844 ?       SLl  May08  22:04 /oracle/crs/bin/ocssd.bin
scu      29189  0.8  0.6  70716 50404 ?        S    May08  79:50 manager 0
scu      29221  1.0  2.8 1239576 230188 ?      S    May08 101:00 scf 0 1
scu      29222  1.0  2.8 1239512 229856 ?      S    May08 100:42 scf 0 2
scu      29223  1.0  2.8 1239676 229924 ?      S    May08  99:58 scf 0 3
scu      29224  1.0  2.8 1239508 230132 ?      S    May08 100:08 scf 0 4
oracle   29339  0.3  7.7 4302156 631128 ?      Ss   May08  31:47 oracleora11g2 (LOCAL=NO)
oracle   29346  0.3  7.7 4302152 631836 ?      Ss   May08  31:49 oracleora11g2 (LOCAL=NO)
oracle   29353  0.3  7.7 4302104 629432 ?      Ss   May08  31:30 oracleora11g2 (LOCAL=NO)
oracle   29360  0.3  7.7 4302112 626524 ?      Ss   May08  31:42 oracleora11g2 (LOCAL=NO)
root     24151  0.3  0.0   8196  3088 ?        S<L  00:00   2:46 /usr/bin/atop -a -w /var/log/atop/atop_20100514 10
oracle   13566  3.0  0.4 4298468 34548 ?       Ss   13:46   0:00 ora_j000_ora11g2
作者: iori809    時(shí)間: 2010-05-14 21:32
awk 'NR>1{total+=$3}END{print total}'
作者: zhangshebao    時(shí)間: 2010-05-14 22:24
本帖最后由 zhangshebao 于 2010-05-14 22:31 編輯
  1. i=1
  2. for [ $i -le 10 ];do
  3. ps pux
  4. echo "END"
  5. i=`expr $i + 1`
  6. done|awk '
  7. {
  8. if ($0=="END"){
  9. if (cpu>0)print "CPU="cpu;
  10. cpu=0;
  11. } else {
  12. cpu+=$3;
  13. }
  14. }'
復(fù)制代碼

找一下你的文件中每個(gè)ps命令之間的分隔有什么特征,如果可以的話,每次ps后增加一個(gè)echo語(yǔ)句告訴awk ps結(jié)束了.
如果不介意下個(gè)ps時(shí)顯示上次ps的結(jié)果,也可以用$1=="USER"或$0==標(biāo)題行作為輸出的條件.
作者: Shell_HAT    時(shí)間: 2010-05-14 22:40
回復(fù) 2# iori809


你沒(méi)有理解樓主的意思吧?
作者: kwokcn    時(shí)間: 2010-05-15 04:25
try:

  1. awk -v RS="\n*bj-djt-win-scp1b scu/bin> ps aux\n|\n" 'NR>2&&s~"\n*bj-djt-win-scp1b scu/bin> ps aux\n"{print n;n=0}NR!=1{n+=$3}{s=RT}END{print n}' URFILE
復(fù)制代碼

作者: iori809    時(shí)間: 2010-05-15 09:08
回復(fù) 4# Shell_HAT


    讓折騰大哥見(jiàn)笑了~呵呵. 我理解需求的能力不行啊~趕緊寫一個(gè)挽回聲譽(yù)
[root@Dan scripts]# awk '{if($0 ~ /CPU/){while(getline tmp > 0){if(tmp ~ /ps/){print total;total=0;getline}else{split(tmp,array);total+=array[3]}}}}END{print total}' linux.142
7.2
7.2
7.2
7.2
10.2
作者: lucash    時(shí)間: 2010-05-15 12:39
awk '/ps aux/&&NR>1{print cpu;cpu=0}{cpu+=$3}END{print cpu}' data
作者: iori809    時(shí)間: 2010-05-15 13:12
回復(fù) 8# lucash


   
作者: XQKA    時(shí)間: 2010-05-17 10:33
ps aux    才十幾行 ?


[oracle@RAC2 ~]$ ps aux | wc -l
275
[oracle@RAC2 ~]$ ps aux | grep -v oracle | wc -l
95




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