2012-02-27

Avoid removals of last columns in redirection of top command

Once a day I tried to redirect a result of top command in batch mode (-b option) with crontab. At that time I toggled many top columns to observe my server machine. But some columns, which are shown the right side of top screen, are not outputted to the specified redirection files.
I investigated this problem and found an essential logic of the top command.
The top command refer to the shell variable of COLUMNS and it regulate the column chars of output. So I adjusted COLUMNS value and I got whole columns successfully in a redirected file.

If you excuse redirection of the top command in batch mode, you should do the following before excuse the top command.
*/10 * * * * export COLUMNS=n;top -b -n 1 >......

No comments:

Post a Comment