0

当我执行命令时

top -c -b -n | grep XXX > TEST

在 Red Hat Linux 命令行上,命令中的所有路径和其余内容top都被导出到TEST文件中(例如,在一行中它写了 100 多列/字符)。

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

如何获取cron脚本中的全宽信息?

4

2 回答 2

1

解释在第 1 节man top

   -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在您启动它和调整其窗口大小时由您的终端设置。

于 2017-05-29T09:26:21.400 回答
0

您可以尝试以下方法:

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

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

礼貌:服务器故障

于 2017-05-29T09:29:28.863 回答