title: Bash Unix | ssh exiting with different user profiles
body: <p>I am working in JAVA, trying to implement a com.sshtools.j2ssh.session.SessionChannelClient successfully.  I find my code works great for people who do not have special commands in their profile like /bin/bash.  Like myself, my profile is bash by default, it works great.  Users however, that are native ksh who add /bin/bash to their profile can't use my code.</p>
  
  <p>Here is the heart of my code...</p>
  
  <pre><code>    try {
          // Build our connection, and connect
          sessionChannelClient = new SessionChannelClient();
          sshClient = new SshClient();
          sshClient.connect(server, new IgnoreHostKeyVerification());
  
          // build authentication, and authenticate
          PasswordAuthenticationClient auth = new PasswordAuthenticationClient();
          auth.setUsername(username);
          auth.setPassword(password);
          int authResult = sshClient.authenticate(auth);
          System.out.println("authResult:" +authResult);
  
          //start working with the session
          sessionChannelClient = sshClient.openSessionChannel();
          SessionOutputReader sor = new SessionOutputReader(sessionChannelClient);
          boolean terminalGood = sessionChannelClient.requestPseudoTerminal("gogrid", 80, 24, 0, 0, "");
          if (!terminalGood){System.out.println("no terminal created..."); return 99;}
  
          if (sessionChannelClient.startShell()) {
  
              //build an in/out so we can see the text to and from unix
              ChannelInputStream channelInputStream = sessionChannelClient.getInputStream();
              ChannelOutputStream channelOutputStream = sessionChannelClient.getOutputStream();
              //System.out.println(in);
  
              // RUN THE COMMAND
              System.out.println("Sending command to UNIX.....");
              channelOutputStream.write(command.getBytes());
              Thread.sleep(1000 * 5);//unix needs time to run the commands
  
              System.out.println("ScriptName | " + script);
              System.out.println("providePassword flag|" + providePassword);
              if( script.equals("propSync.shl")|| script.equals("nonsrcSync.shl")){providePassword = false;}
  
              //The java app called by the script needs a password
              if (providePassword) {
                  channelOutputStream.write(tempPassword.getBytes());
                  Thread.sleep(1000 * 3);//unix needs time to run the commands
              }
              else{ System.out.println("providePassword not required it seems for --&gt;" + script); }
  
              // Close the channel
              String exit = "exit\n";
              while(sessionChannelClient.getState().getValue() != ChannelState.CHANNEL_CLOSED){
                  System.out.println("lets try to exit the sessionChannelClient...." + sessionChannelClient.getState().getValue());
                  channelOutputStream.write(exit.getBytes()); // without this, it wont log out correctly
                  Thread.sleep(1000 * 5);//unix needs time to run the commands
              }
              exitCode = sessionChannelClient.getExitCode();
              System.out.println("just outside of while loop SessionState:" + sessionChannelClient.getState().getValue());
              System.out.println("just outside of while loop EXITCODE:" + exitCode);
              sessionChannelClient.close();
          } 
          else { System.out.println("the shell refused to start"); return 99;}
      } 
      catch (Exception e) { printOUtMessages(e, "Exception", script, server, command); return 99;} 
      finally { sshClient.disconnect(); }
  
      //Wrap up and return back
      calculateTime(startTime, exitCode, baseMessage);
      return exitCode; // non-zero means failure
  </code></pre>