库ssh.net的问题 [英] Problem with Library ssh.net

查看:99
本文介绍了库ssh.net的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各个团体



我正在使用这个库来连接我运行和运行的Linux命令但是

一些命令有问题



例如,我在运行这些命令时遇到问题:



top和top -n 1



错误:未设置TERM环境变量。





< pre lang =c#> 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( 顶部);

var line = command.Result.Split(' \\\
');
List< ServerStatusCpu> serverstatus = new 列表< 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 ]。替换( ));
serverStatus.UserNiceCpuTime = float .Parse(fillterwords [ 4 ]。替换( ));
serverStatus.SystemCpuTime = float .Parse(fillterwords [ 5 ]。替换( ));
serverStatus.IoWaitCpuTime = float .Parse(fillterwords [ 6 ]。替换( ));
serverStatus.IrqCpuTime = float .Parse(fillterwords [ 7 ]。替换( ));
serverStatus.SoftwareIrqCpuTime = float .Parse(fillterwords [ 8 ]。替换( ));
serverStatus.StealCpuTime = float .Parse(fillterwords [ 9 ]。替换( ));
serverStatus.GuestCpuTime = float .Parse(fillterwords [ 10 ]。替换( ));
serverStatus.IdleCpuTime = float .Parse(fillterwords [ 11 ]。替换( ));

serverstatus.Add(serverStatus);
}

dataGridView1.DataSource = serverstatus;
}





class ServerStatusCpu



  public   class  ServerStatusCpu 
{
public string 时间{ get ; set ; }

public string TimeType {获得; set ; }

public string 名称{获得; set ; }

public float UserCpuTime {获得; set ; }

public float SystemCpuTime {获得; set ; }

public float UserNiceCpuTime {获得; set ; }

public float IdleCpuTime {获得; set ; }

public float IoWaitCpuTime {获得; set ; }

public float IrqCpuTime {获得; set ; }

public float SoftwareIrqCpuTime {获得; set ; }

public float StealCpuTime {获得; set ; }

public float GuestCpuTime {获得; set ; }
}

解决方案

log98写道:

错误:未设置TERM环境变量。

这是一条shell消息。 Linux需要知道您登录的终端类型,以便显示任何输出。这通常由首次登录系统时运行的默认或用户登录脚本自动设置。我不确定上面的代码是做什么的,但是你需要在实际命令运行之前找到一些获取这个设置的方法。


hi every body

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

For example, I have a problem running these commands:

top and top -n 1

error:TERM environment variable not set.


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

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; }
    }

解决方案

log98 wrote:

error:TERM environment variable not set.

This is a shell message. Linux needs to know which terminal type you are logged in from, in order to display any output. This is usually set automatically by the default, or user, login script, that is run when you first login to the system. I''m not sure what the above code is trying to do, but you need to find some way of getting this set before the actual command runs.


这篇关于库ssh.net的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆