[英]Bash script output of a top command
When I execute command 当我执行命令
top -c -b -n | grep XXX > TEST
on Red Hat Linux command line, all the paths and the rest of the stuff from the top
command is exported into the TEST
file (in one line it wrote more than 100 columns/character, for example). 在Red Hat Linux命令行上,来自top
命令的所有路径和其余内容都导出到TEST
文件中(例如,在一行中,它写了100多个列/字符)。
However, when I add the same command in a script and run it via crontab
, the output is every time only until the 81 column/character. 但是,当我在脚本中添加相同的命令并通过crontab
运行它时,输出每次仅直到81列/字符为止。
How can I get the full width information in the cron
script? 如何在cron
脚本中获取全宽信息?
The explanation is in section 1 of man top
: 解释在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.
COLUMNS
and LINES
are set by your terminal when you start it and when you resize its window. 终端在启动时以及在调整窗口大小时会设置COLUMNS
和LINES
。
You could try the following: 您可以尝试以下方法:
COLUMNS=1000 top -c -b -n 1 | grep XXX > TEST
This will ensure that COLUMNS environment variable value is set to a large value. 这将确保将COLUMNS环境变量值设置为较大的值。
Courtesy: ServerFault 礼貌: ServerFault
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.