top命令的Bash脚本输出

时间:2017-05-29 09:18:39

标签: bash shell file-io top-command

执行命令时

Annotation Processors

在Red Hat Linux命令行上,top -c -b -n | grep XXX > TEST 命令中的所有路径和其余内容都被导出到top文件中(在一行中它写了超过100列/字符,例如)。

但是,当我在脚本中添加相同的命令并通过TEST运行时,输出每次只有81列/字符。

如何在crontab脚本中获取全宽信息?

2 个答案:

答案 0 :(得分:1)

解释见man top的第1部分:

   -w  :Output-width-override as:  -w [ number ]
        In  Batch  mode, when used without an argument top will
        format output using the COLUMNS= and LINES= environment
        variables,  if  set.  Otherwise, width will be fixed at
        the maximum 512  columns.   With  an  argument,  output
        width can be decreased or increased (up to 512) but the
        number of rows is considered unlimited.

        In normal display mode, when used without  an  argument
        top  will  attempt  to format output using the COLUMNS=
        and LINES= environment  variables,  if  set.   With  an
        argument,  output  width  can  only  be  decreased, not
        increased.  Whether using environment variables  or  an
        argument  with -w, when not in Batch mode actual termi‐
        nal dimensions can never be exceeded.

        Note: Without the use of this command-line option, out‐
        put  width is always based on the terminal at which top
        was invoked whether or not in Batch mode.
当您启动它并调整其窗口大小时,终端会设置

COLUMNSLINES

答案 1 :(得分:0)

您可以尝试以下方法:

COLUMNS=1000 top -c -b -n 1  | grep XXX > TEST

这将确保将COLUMNS环境变量值设置为较大的值。

礼貌:ServerFault