top output to narrow in cron

Solution 1:

Use the -w switch for 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= envi‐
        ronment  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 ter‐
        minal dimensions can never be exceeded.

        Note: Without the use  of  this  command-line  option,
        output  width is always based on the terminal at which
        top was invoked whether or not in 'Batch' mode.

Solution 2:

Thanks Sven but my output for top is this:

# top -w
top: unknown argument 'w'

I guess you have a more recent version. But you sent me in right direction(+1 for you): I changed my script to export the number on columns and now I have full output:

#!/bin/bash

trigger=15.00

load=`cat /proc/loadavg | awk '{print $1}'`

response=`echo | awk -v T=$trigger -v L=$load 'BEGIN{if ( L > T){ print "greater"}}'`

if [[ $response = "greater" ]]
then
#sar -q | mail -s"High load on server - [ $load ]" [email protected]
export COLUMNS=512
top -cSbn 1 | head -14 | tail -14 | mail -s"High load on server YODA - [ $load ]" [email protected]
fi