private void ReadingSSH() { try { if (intServer > 0) { string strRegularExpression = oModel.GetBootGroup(intModelBootGroup, "regular"); DataSet dsSSH = oModel.GetBootGroupStepNext(intModel, intServer); bool boolCondition = false; string strResultCondition = ""; string strResultSSH = ""; for (int ii = 0; ii < dsSSH.Tables[0].Rows.Count && oSSHshell.Connected == true && oSSHshell.ShellOpened == true; ii++) { string strWriteSSH = dsSSH.Tables[0].Rows[ii]["then_write"].ToString(); bool boolPower = (dsSSH.Tables[0].Rows[ii]["power"].ToString() == "1"); datStart = DateTime.Now; intTimeoutStep = Int32.Parse(dsSSH.Tables[0].Rows[ii]["id"].ToString()); intTimeout = Int32.Parse(dsSSH.Tables[0].Rows[ii]["timeout"].ToString()); string strConditionSSH = dsSSH.Tables[0].Rows[ii]["wait_for"].ToString(); if (boolPower == true) { // Power on step completed, move to next step AddResult(""); oEventLog.AddEvent(strName, strSerial, "POWER ON command sent...moving to next step", LoggingType.Information); } // Wait to execute next command if (boolCondition == false) { DateTime datBegin = DateTime.Now; oEventLog.AddEvent(strName, strSerial, "Waiting for response... (timeout = " + intTimeout.ToString() + " minutes) (Expression = " + strRegularExpression + ")", LoggingType.Information); strResultSSH = ReplaceGarbageChars(oSSHshell.Expect(strRegularExpression)); strSSH += strResultSSH; TimeSpan oSpan = DateTime.Now.Subtract(datBegin); oEventLog.AddEvent(strName, strSerial, "Received Response... (took " + oSpan.TotalSeconds.ToString("0") + " seconds)", LoggingType.Information); // ********************************************************************************************************************** // The following lines should be coded for specific models. The point of the "strReturnToALOM" is to exit out of the // console once commands are sent, otherwise the console will show in use and the session might not close properly. // ********************************************************************************************************************** // START: T6320 / T6340 if (strResultSSH.Contains("to return to ALOM") == true && strReturnToALOM == "") { strReturnToALOM = oSolaris.ParseOutput(strResultSSH, "Enter", "to return to ALOM"); } // END: T6320 / T6340 } else { strResultSSH = strResultCondition; strResultCondition = ""; } if (strConditionSSH == "" || strResultSSH.Contains(strConditionSSH) == true) { boolCondition = false; if (oSSHshell.Connected == true && oSSHshell.ShellOpened == true) { // Execute next command oEventLog.AddEvent(strName, strSerial, "Writing command : " + strWriteSSH, LoggingType.Information); oSSHshell.WriteLine(strWriteSSH); oEventLog.AddEvent(strName, strSerial, "Completed command : " + strWriteSSH, LoggingType.Information); } else { oEventLog.AddEvent(strName, strSerial, "oSSHshell has been closed...unable to write: " + strWriteSSH, LoggingType.Information); } } else { // The conditional statement was not found, move to next step... boolCondition = true; strResultCondition = strResultSSH; strResultSSH = ""; } // Update database oServer.AddOutput(intServer, strWriteSSH, strResultSSH); } // Either all commands are done, or the oSSHshell object was closed (due to error or timeout) if (oSSHshell.Connected == true && oSSHshell.ShellOpened == true) { oEventLog.AddEvent(strName, strSerial, "Exited Step Configuration...waiting for last ouput...", LoggingType.Information); // All commands are done - get the last output strResultSSH = ReplaceGarbageChars(oSSHshell.Expect(strRegularExpression)); oEventLog.AddEvent(strName, strSerial, "Got Last Output", LoggingType.Information); strSSH += strResultSSH; // If applicable, run the "strReturnToALOM" command if (strReturnToALOM != "") { if (oSSHshell.Connected == true && oSSHshell.ShellOpened == true) { oEventLog.AddEvent(strName, strSerial, "Writing command : " + strReturnToALOM, LoggingType.Information); // Write command oSSHshell.WriteLine(strReturnToALOM); oEventLog.AddEvent(strName, strSerial, "Completed command : " + strReturnToALOM, LoggingType.Information); // Update database oServer.AddOutput(intServer, strReturnToALOM, strResultSSH); // And get the "strReturnToALOM" output oEventLog.AddEvent(strName, strSerial, "Waiting for return output... ", LoggingType.Information); strResultSSH = ReplaceGarbageChars(oSSHshell.Expect(strRegularExpression)); oEventLog.AddEvent(strName, strSerial, "Got return output...", LoggingType.Information); strSSH += strResultSSH; } } } else { // oSSHshell object was closed (due to error or timeout) - do nothing more... oEventLog.AddEvent(strName, strSerial, "oSSHshell object was already closed... ", LoggingType.Information); } // Close the oSSHshell object if (oSSHshell.Connected == true || oSSHshell.ShellOpened == true) { oSSHshell.Close(); oEventLog.AddEvent(strName, strSerial, "oSSHshell was closed... ", LoggingType.Information); } oEventLog.AddEvent(strName, strSerial, "Exited ReadingSSH Loop for SERVERID = " + intServer.ToString(), LoggingType.Information); } } catch (Exception ex) { string strError = "Physical Service (SolarisBuild - ReadingSSH): " + "(Error Message: " + ex.Message + ") (Source: " + ex.Source + ") (Stack Trace: " + ex.StackTrace + ") [" + System.Environment.UserName + "]"; SystemError(intServer, intStep, strError, intAsset, intModel); } }