Maybe you have tried to execute the top command to monitor processes on a remote host.

Error remotely – Run it in batch mode

If so, the following error can be returned:

$ ssh user@remotehost top -n1
TERM environment variable not set.

top does not work remotely in the default “interactive” mode. Use the “-b” parameter to run it in batch mode:

$ ssh user@remotehost top -n1 -b
top - 15:06:51 up 56 days, 23:10,  2 users,  load average: 2.04, 1.57, 1.19
Tasks:  80 total,   1 running,  79 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.6%us,  3.1%sy, 15.2%ni, 77.4%id,  1.5%wa,  0.0%hi,  0.2%si,  0.0%st
Mem:   2076392k total,  1882296k used,   194096k free,   145952k buffers
Swap:  1124508k total,      584k used,  1123924k free,   939080k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      20   0  2104  688  588 S    0  0.0  10:07.29 init
    2 root      15  -5     0    0    0 S    0  0.0   0:00.00 kthreadd
    3 root      RT  -5     0    0    0 S    0  0.0   2:57.19 migration/0
...

Customize output

In addition to access remotely, maybe we also need certain customized top output.
So, prior to do the remote calls, I can execute the top command locally in interactive mode and configure it, for example, to show threads (Shift+”h”), to show all cpus/cores separately (“1”), …

Top command - show threads

and save this customization by pressing Shift+w

Top command - save configuration

Then, each time top command is executed using the same user on that machine there is no need to customize it again. When ran remotely the output is also customized.

$ ssh user@remotehost top -n1 -b
top - 15:27:46 up 56 days, 23:31, 2 users, load average: 0.82, 0.87, 0.84
Tasks: 101 total, 1 running, 100 sleeping, 0 stopped, 0 zombie
Cpu0 : 2.5%us, 3.0%sy, 16.1%ni, 76.7%id, 1.4%wa, 0.0%hi, 0.3%si, 0.0%st
Cpu1 : 2.6%us, 3.1%sy, 14.4%ni, 78.1%id, 1.7%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 2076392k total, 1885504k used, 190888k free, 146028k buffers
Swap: 1124508k total, 584k used, 1123924k free, 940064k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2278 root 20 0 5524 2832 2340 S 2.0 0.1 68:38.97 vmtoolsd
1 root 20 0 2104 688 588 S 0.0 0.0 10:07.42 init
2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT -5 0 0 0 S 0.0 0.0 2:57.23 migration/0
4 root 15 -5 0 0 0 S 0.0 0.0 7:23.32 ksoftirqd/0
5 root RT -5 0 0 0 S 0.0 0.0 0:05.40 watchdog/0

Now you can send it to a file, pipe, parse it, schedule command…