Package org.jclouds.sshj

Examples of org.jclouds.sshj.SshjSshClient.exec()


    Assert.hasText(fileName, "The remote file name must be specified.");
    boolean isFileCopied = false;
    long timeout = System.currentTimeMillis() + retryTime;
    while (!isFileCopied && System.currentTimeMillis() < timeout) {
      SshjSshClient client = getSSHClient(host, privateKey);
      client.exec("mkdir " + dir);
      client.put(dir + "/" + fileName, payload);
      ExecResponse response = client.exec("ls -al " + dir + "/" + fileName);
      if (response.getExitStatus() > 0) {
        continue; //file was not created
      }
View Full Code Here


    long timeout = System.currentTimeMillis() + retryTime;
    while (!isFileCopied && System.currentTimeMillis() < timeout) {
      SshjSshClient client = getSSHClient(host, privateKey);
      client.exec("mkdir " + dir);
      client.put(dir + "/" + fileName, payload);
      ExecResponse response = client.exec("ls -al " + dir + "/" + fileName);
      if (response.getExitStatus() > 0) {
        continue; //file was not created
      }
      response = client.exec("cat " + dir + "/" + fileName);
      if (response.getExitStatus() > 0 || !payload.equals(response.getOutput())) {
View Full Code Here

      client.put(dir + "/" + fileName, payload);
      ExecResponse response = client.exec("ls -al " + dir + "/" + fileName);
      if (response.getExitStatus() > 0) {
        continue; //file was not created
      }
      response = client.exec("cat " + dir + "/" + fileName);
      if (response.getExitStatus() > 0 || !payload.equals(response.getOutput())) {
        continue;//data stored on machine is different than was expected.
      }
      isFileCopied = true;
    }
View Full Code Here

      }
      catch (IOException ioe) {
        throw new IllegalStateException("Unable to retrieve size for file to be copied to remote machine.", ioe);
      }
      client.put(uri.getPath(), payload);
      if (client.exec("ls -al " + uri.getPath()).getExitStatus() == 0) {
        ExecResponse statResponse = client.exec("stat --format=%s " + uri.getPath());
        long copySize = Long.valueOf(statResponse.getOutput().trim());
        if (copySize == byteSourceSize) {
          isFileCopied = true;
        }
View Full Code Here

      catch (IOException ioe) {
        throw new IllegalStateException("Unable to retrieve size for file to be copied to remote machine.", ioe);
      }
      client.put(uri.getPath(), payload);
      if (client.exec("ls -al " + uri.getPath()).getExitStatus() == 0) {
        ExecResponse statResponse = client.exec("stat --format=%s " + uri.getPath());
        long copySize = Long.valueOf(statResponse.getOutput().trim());
        if (copySize == byteSourceSize) {
          isFileCopied = true;
        }
      }
View Full Code Here

    Assert.hasText(host, "host must not be empty nor null");
    Assert.hasText(privateKey, "privateKey must not be empty nor null");
    long timeout = System.currentTimeMillis() + waitTime;
    while (!isDirectoryCreated && System.currentTimeMillis() < timeout) {
      SshjSshClient client = getSSHClient(host, privateKey);
      client.exec("mkdir " + path);
      ExecResponse response = client.exec("ls -al " + path);
      if (response.getExitStatus() > 0) {
        continue; //directory was not created
      }
      isDirectoryCreated = true;
View Full Code Here

    Assert.hasText(privateKey, "privateKey must not be empty nor null");
    long timeout = System.currentTimeMillis() + waitTime;
    while (!isDirectoryCreated && System.currentTimeMillis() < timeout) {
      SshjSshClient client = getSSHClient(host, privateKey);
      client.exec("mkdir " + path);
      ExecResponse response = client.exec("ls -al " + path);
      if (response.getExitStatus() > 0) {
        continue; //directory was not created
      }
      isDirectoryCreated = true;
    }
View Full Code Here

    Assert.hasText(host, "The remote machine's URL must be specified.");
    Assert.notNull(dir, "dir should not be null");
    Assert.hasText(fileName, "The remote file name must be specified.");

    final SshjSshClient client = getSSHClient(host, privateKey);
    client.exec("echo '" + payload + "' >> " + dir + "/" + fileName);
  }

  /**
   * Returns a list of active instances from the specified ec2 region.
   * @param awsAccessKey the unique id of the ec2 user.
View Full Code Here

   */
  public static Integer[] getContainerPidsFromURL(URL url, String privateKey, String jpsCommand) {
    Assert.notNull(url, "url can not be null");
    Assert.hasText(privateKey, "privateKey can not be empty nor null");
    SshjSshClient client = getSSHClient(url, privateKey);
    ExecResponse response = client.exec(jpsCommand);
    return extractPidsFromJPS(response.getOutput());
  }

  private static Integer[] extractPidsFromJPS(String jpsResult) {
    String[] pidList = StringUtils.tokenizeToStringArray(jpsResult, "\n");
View Full Code Here

      SshClient ssh = new SshjSshClient(new BackoffLimitedRetryHandler(), socket, 60000, credentials.identity, null,
               credentials.credential.getBytes());
      try {
         ssh.connect();
         ExecResponse hello = ssh.exec("echo hello");
         assertEquals(hello.getOutput().trim(), "hello");
         ExecResponse exec = ssh.exec("df");
         assertTrue(exec.getOutput().contains("Filesystem"),
                  "The output should've contained filesystem information, but it didn't. Output: " + exec);
      } finally {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.