我用下面的bash腳本面對:bash腳本給不需要的輸出
#! /bin/bash
processname=$1
x=1
while [ $x -eq 1 ] ; do
ps -el | grep $processname | awk ' {if($15!="grep") print "The memory consumed by the process " $15 " is = "$9} ' >> out.log
sleep 30
done
,我與運行以下命令:
$ ./myscript.sh Firefox
,但是當我看到文件中的輸出,除了該firefox
過程中我也得到信息/bin/bash
過程
The memory consumed by the process /Applications/Firefox.app/Contents/MacOS/firefox is = 911328
The memory consumed by the process /bin/bash is = 768
有人可以幫助我,因此我只想獲取有關Firefox進程的信息(/bin.bash等)
好實現它,我嘗試這樣做,它也可以工作: PS -el | grep $ processname | awk'{if($ 15!=「grep」)print「進程使用的內存」$ 15「is =」$ 9}'| grep -v/bin/bash >> out.log – lancelot 2012-02-10 13:10:35