[Solved] Cant get message body

Hi guys . I am trying to take the output of top command and mail it to myself . The code is :

echo ##############################################################

/usr/local/bin/top c n 1 b >> /export/home/top-output.txt
echo ##############################################################


WT_TO=`tail -22 /export/home/top-output.txt`


cat $WT_TO | mailx -s "Top Command OutPut" myemail@address.com

The body is empty ! Whereas if i open the txt file , I do get an output.

Hi,
there is a little mistake. Try:

echo $WT_TO | mailx -s "Top Command OutPut" myemail@address.com
echo "$WT_TO" | mailx -s "Top Command OutPut" myemail@address.com

Or in one stroke:

tail -22 /export/home/top-output.txt |
mailx -s "Top Command OutPut" myemail@address.com

Thankyou . It does work but it sends data in this form :

load averages: 14.5, 15.4, 15.9; up 3+20:00:34 22:41:00 1238 processes: 1212 sleeping, 1 running, 1 zombie, 24 on cpu CPU states: 56.0% idle, 13.2% user, 30.8% kernel, 0.0% iowait, 0.0% swap Memory: 96G phys mem, 8761M free mem, 96G total swap, 95G free swap PID USERNAME LWP PRI NICE SIZE RES STATE TIME CPU COMMAND 464 root 72 49 0 24M 16M cpu/65 865:42 2.59% nscd 16862 dbm 1 0 2 1752K 1272K sleep 0:01 2.02% mv 27068 oracle 1 32 0 4250M 4233M cpu/64 403:25 1.96% oracle 142 oracle 258 46 0 45G 3326M sleep 143:41 1.05% oracle 140 oracle 258 54 0 45G 3327M sleep 148:54 0.91% oracle 29014 oracle 11 0 0 45G 27G sleep 65:18 0.76% oracle 10837 oracle 11 37 0 45G 27G sleep 0:08 0.74% oracle 4439 oracle 11 2 0 10G 10G sleep 40:35 0.55% oracle 16961 tcs 1 0 2 1928K 1616K sleep 0:00 0.51% ps 16951 tcs 1 0 2 1928K 1616K cpu/48 0:00 0.51% ps 16947 tesb 1 0 2 1928K 1616K sleep 0:00 0.51% ps 16960 tcs 1 0 2 1928K 1616K sleep 0:00 0.50% ps 17083 tesb 1 0 2 1928K 1616K cpu/74 0:00 0.48% ps 1!
 5694 tcs 11 60 2 45G 27G sleep 20:13 0.43% oracle 17037 tcs 1 0 2 1928K 1616K sleep 0:00 0.43% ps

Whereas it should be in the form :

load averages:  19.0,  19.4,  19.9;                    up 3+18:54:16   21:34:42
1084 processes: 1074 sleeping, 1 running, 1 zombie, 8 on cpu
CPU states: 74.1% idle, 13.9% user, 11.9% kernel,  0.0% iowait,  0.0% swap
Memory: 96G phys mem, 8168M free mem, 96G total swap, 95G free swap

   PID USERNAME LWP PRI NICE  SIZE   RES STATE    TIME    CPU COMMAND
 12383 dbm        1   0    2 2000K 1456K cpu/9    0:02  1.95% gzip
 29014 oracle    11   2    0   45G   27G cpu/0   33:54  1.40% oracle
  4439 oracle    11  59    0   10G   10G cpu/3    4:56  1.21% oracle
 12503 dbm        1  60    2 2000K 1456K sleep    0:00  0.91% gzip
    90 oracle     1  20    0   45G 2390M run    767:35  0.78% oracle
 14178 oracle    11  60    0   45G   27G sleep    0:12  0.63% oracle
 12687 oracle    11  39    0   45G   27G sleep    0:11  0.46% oracle
 27239 root      11 100  -20  230M  201M sleep  596:23  0.41% osysmond.bin
  1004 tesb      54  53    2 3908M 1303M sleep   43:11  0.36% java
  8066 oracle     1   5    0   45G   27G sleep    0:05  0.35% oracle
 15694 tcs       11  60    2   45G   27G sleep    8:57  0.33% oracle
  7477 oracle    35  60    0   45G   27G sleep    1:21  0.33% oracle
  2234 oracle     1  30    0   10G   10G sleep  581:10  0.30% oracle
  2268 oracle   258  32    0   10G   10G sleep  177:43  0.30% oracle
  1727 tcs       43  53    2  354M  278M sleep   47:07  0.29% java

Run as suggested by MadeInGermany:

tail -22 /export/home/top-output.txt | mailx -s "Top Command OutPut" yemail@address.com

Using MadeInGermany's code:

tail -22 /export/home/top-output.txt | \unix2dos |
mailx -s "Top Command OutPut" myemail@address.com

use ux2dos or unix2dos depending of your OS...

Works like a charm. Thankyou all !