Reputation: 137
I am writing a shell script where i want to ssh to a server and get the cpu and memory details data of that displayed as a result. I’m using the help of top
command here.
Script line:
ssh -q user@host -n “cd; top -n 1 | egrep ‘Cpu|Mem|Swap’”
But the result is
TERM environment variable is not set.
I had checked the same in the server by entering set | grep TERM
and got result as TERM=xterm
Please someone help me on this. Many thanks.
Upvotes: 1
Views: 6663
Reputation: 137
Got it..!! Need to make a small modification for the below script line.
ssh -t user@host -n "top -n 1 | egrep 'Cpu|Mem|Swap'"
Instead of -t
we need to give -tt
. It worked for me.
To execute command top after ssh’ing. It requires a tty to run. Using -tt it will enable a force pseudo-tty allocation.
Thanks stony for providing me a close enough answer!! :)
Upvotes: 0
Reputation: 27295
top
need an environment. You have to add the parameter -t
to get the result:
ssh -t user@host -n "top -n 1 | egrep 'Cpu|Mem|Swap'"
Upvotes: 3
Reputation: 2401
Try using the top -b
flag:
ssh -q user@host -n "cd; top -bn 1 | egrep 'Cpu|Mem|Swap'"
This tells top to run non-interactively, and is intended for this sort of use.
Upvotes: 2