Results 1 to 1 of 1

Thread: VS2015 Renci SSH.NET Unable to kill a process on AIX server with PowerBroker access

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    7

    VS2015 Renci SSH.NET Unable to kill a process on AIX server with PowerBroker access

    Hi guys,

    Tried this question on StackOverflow with no luck, giving it a shot here:

    I'm trying to develop a Windows Form in VB.NET which can connect to an AIX server and retrieve the PID#'s for certain processes. The PID#'s are then stored in a DataGrid. The Windows Form also needs to be able to kill those PIDs if the user clicks a button on the form. The hitch is the PIDs are running as a different user account than the account I am using to SSH into the server with. The account I am using does however have PowerBroker access to the user account which owns the PIDs. I'm using Renci SSH.NET

    Code to get the PID (this works fine and loads the PIDS into my DataGrid):

    Code:
    Private Sub getKILLPID()
        Dim newDataRow = killGrid.Rows(0)
        Dim pid As String
        Dim child As String
        Dim connInfo As New Renci.SshNet.PasswordConnectionInfo(ApplicationVariablesModule.serverName, ApplicationVariablesModule.psUsername, ApplicationVariablesModule.psPassword)
        Dim sshClient As New Renci.SshNet.SshClient(connInfo)
        Dim cmd As Renci.SshNet.SshCommand
        Using sshClient
            sshClient.Connect()
            cmd = sshClient.RunCommand("ps -ef | grep process_name  | grep -v grep | awk '{print $2}'")
            pid = cmd.Result.ToString
            cmd = sshClient.RunCommand("ps -ef | grep process_name  | grep -v grep | awk '{print $3}'")
            child = cmd.Result.ToString
            If pid.Length < 1 Then
                newDataRow.Cells(1).Value = "DOWN"
                newDataRow.Cells(2).Value = "n/a"
            Else
                newDataRow.Cells(1).Value = pid
                newDataRow.Cells(2).Value = child
            End If
    Code which is failing to kill the PIDs:

    Code:
    Dim connInfo As New Renci.SshNet.PasswordConnectionInfo(ApplicationVariablesModule.serverName, ApplicationVariablesModule.psUsername, ApplicationVariablesModule.psPassword)
        Dim sshClient As New Renci.SshNet.SshClient(connInfo)
        Dim cmd As Renci.SshNet.SshCommand
    
            Using sshClient
                sshClient.Connect()
                cmd = sshClient.RunCommand("pbrun -u username /usr/bin/kill -9 " & pid)
                sshClient.Disconnect()
            End Using
    End Sub
    After I click on the button on the windows form nothing happens. If I login to the AIX server using PuTTy I can still see the process running. If I issue the exact same command thru PuTTy it works fine. I've checked the .sh_history file on the AIX server and there is no evidence the command was even executed on the server.

    One other thing I've tried is to just write a .ksh script on the AIX server and let it kill the processes:

    Code:
    pids=`ps -ef | grep process_name | grep -v grep | awk '{print $2}'`
    if [[ $pids != "" ]] then
      pbrun -u user /usr/bin/kill -9 $pids
      if [[ $? -ne 0 ]] then
        echo "Error killing process: $pids \n">>/home/user/logs/kill.log
        echo "Return code was: $?">>/home/user/logs/kill.log
        exit -1
     else
        echo "All process were successfully killed!\n">>/home/user/logs/kill.log
     fi
    fi
    Again, if I execute this .ksh script directly on the AIX server logging in via PuTTy w/ SSH it runs fine. But when I attempt to execute the script with SSH.NET thru my VB form

    Code:
    cmd = sshClient.RunCommand("cd /home/user/scripts; ./kill_process.ksh;")
    it throws the error:

    Code:
    servername:/home/user/logs $ cat kill.log
    Fri Aug 17 15:06:51 CDT 2018
    Error killing process: 9699556
    
    Return code was: 0
    So my hunch is the problem lies somewhere in the permissions allowed between the Renci.dll used in my VBP Project and the AIX server.
    I've read similar posts online about people having trouble with ssh.net and issuing SUDO commands, and the answer is always because sudo is interactive and requires username and password you need a TTY emulator. However in my scenario I'm using powerbroker to change user accounts and hence no password is required to be given interactively. Anyone come across this scenario before or know any work-arounds?
    Last edited by BRoetzer; Aug 20th, 2018 at 12:48 PM. Reason: Adding Visual Studio Version to the Title

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width