我使用這個庫連接到Linux命令我就跑,但 一些命令有問題如何通過SSH正確運行「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; }
}
}
此外,當您通過SSH連接到機器並手動調用命令時會發生什麼? – 2013-05-14 13:13:31
感謝您的回答 我看到你已經把一個鏈接,但我的問題並沒有解決我的問題,因爲這個事件 這就是當我連接到Lyvnks和我運行這個命令-bn1頂部 我只是不精確top或top-i命令或其他命令top -n 2我的問題 不解決請告訴我如何解決此問題ssh.net庫 謝謝 – Martin 2013-05-14 18:20:05
如何在top -yourargs> outputfile中運行某些內容,然後讀取輸出文件的轉儲? – 2013-05-15 07:12:49