+ -
当前位置:首页 → 问答吧 → top命令在while循环中失效,什么原因?

top命令在while循环中失效,什么原因?

时间:2011-05-16

来源:互联网

代码:

#!/bin/bash

name=test

while read aa
do
result=`top -u "$name" -n 1 | awk '{ if( $0 ~ /'"$name"'/ ) print }'`
echo "$result"
done<ss


显示错误:
top: failed tty get


如果把while循环去掉就正常。

作者: zcsgamer   发布时间: 2011-05-16

加个-b 选项:


QUOTE:
-b : Batch mode operation
   Starts  top  in  <A1><AF>Batch mode<A1><AF>, which could be useful for sending output from top to other programs or to a file.  In this mode, top will not accept input and runs until the iterations limit you<A1><AF>ve set with the <A1><AF>-n<A1><AF> command-line option or until killed.

  1. top -bn 1
复制代码

作者: xiaopan3322   发布时间: 2011-05-16

太感谢了!

作者: zcsgamer   发布时间: 2011-05-16