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