LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2013, 11:15 AM   #1
post98
LQ Newbie
 
Registered: May 2013
Posts: 1

Rep: Reputation: Disabled
How to properly run “top” command through SSH?


hi every body

I'm using this library ssh.net to connect to the Linux commands I run and run but
Some commands have problems

I have to run top command on one computer being on another. My targeted PC has IP 192.168.150.128
I was trying to do it: ssh 192.168.150.128 top

For example, I have a problem running these commands:

top and top -n 1

error:TERM environment variable not set.

my c# code for connected with ssh used library ssh.net


Code:
 private void button2_Click(object sender, EventArgs e)
        {
            Renci.SshNet.SshClient sshClient = new Renci.SshNet.SshClient("192.168.150.128", "reza", "1");
            sshClient.Connect();
            var command = sshClient.RunCommand("top");
 
            var line = command.Result.Split('\n');
            List<ServerStatusCpu> serverstatus = new List<ServerStatusCpu>();
            for (int i = 3; i < line.Length - 1; i++)
            {
                var li = line[i];
                var words = li.Split(' ');
                List<string> fillterwords = new List<string>();
 
                foreach (var w in words)
                {
                    if (w != "")
                    {
                        fillterwords.Add(w);
                    }
                }
 
                ServerStatusCpu serverStatus = new ServerStatusCpu();
                serverStatus.Time = fillterwords[0];
                serverStatus.TimeType = fillterwords[1];
                serverStatus.Name = fillterwords[2];
                serverStatus.UserCpuTime = float.Parse(fillterwords[3].Replace("%", ""));
                serverStatus.UserNiceCpuTime = float.Parse(fillterwords[4].Replace("%", ""));
                serverStatus.SystemCpuTime = float.Parse(fillterwords[5].Replace("%", ""));
                serverStatus.IoWaitCpuTime = float.Parse(fillterwords[6].Replace("%", ""));
                serverStatus.IrqCpuTime = float.Parse(fillterwords[7].Replace("%", ""));
                serverStatus.SoftwareIrqCpuTime = float.Parse(fillterwords[8].Replace("%", ""));
                serverStatus.StealCpuTime = float.Parse(fillterwords[9].Replace("%", ""));
                serverStatus.GuestCpuTime = float.Parse(fillterwords[10].Replace("%", ""));
                serverStatus.IdleCpuTime = float.Parse(fillterwords[11].Replace("%", ""));
 
                serverstatus.Add(serverStatus);
            }
 
            dataGridView1.DataSource = serverstatus;
        }

class ServerStatusCpu

Code:
public class ServerStatusCpu
    {
        public string Time { get; set; }
 
        public string TimeType { get; set; }
 
        public string Name { get; set; }
 
        public float UserCpuTime { get; set; }
 
        public float SystemCpuTime { get; set; }
 
        public float UserNiceCpuTime { get; set; }
 
        public float IdleCpuTime { get; set; }
 
        public float IoWaitCpuTime { get; set; }
 
        public float IrqCpuTime { get; set; }
 
        public float SoftwareIrqCpuTime { get; set; }
 
        public float StealCpuTime { get; set; }
 
        public float GuestCpuTime { get; set; }
    }
thank you
 
Old 05-13-2013, 01:21 PM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
well, what about «env TERM=linux top»?
 
Old 05-13-2013, 02:25 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Either set the TERM environment variable, or use the -b flag in top. My guess is you're just looking for the -b flag which turns off top's fancy formatting.

Last edited by suicidaleggroll; 05-13-2013 at 02:26 PM.
 
Old 05-14-2013, 07:06 AM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: Slackware®
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Moderator Response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
No output from top command run by crontab Gr1f1S Linux - Newbie 5 04-23-2013 05:47 AM
more xfce 4.10 startup/shutdown scripts or run properly {gpg|ssh}-agent rpetrov Slackware - Installation 1 12-03-2012 02:16 AM
firefox doesn't show up properly when run remotely through ssh -Y nass Slackware 12 04-06-2012 10:09 AM
SCP command is not working properly due to SSH enabled musammil123 Linux - Server 1 05-27-2011 03:57 PM
[SOLVED] top command not found while using ssh vikas027 Programming 8 10-24-2007 07:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration