loadrunner java ssh

时间:2021-11-07 19:30:38

s

D:\TestCase\20170703_docker_rongqiyun\tc_docker_ssh_docker_push\Actions.java

/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/ import lrapi.lr;
import java.io.IOException;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session; public class Actions
{
/*
String server = "10.19.95.19";
String server = "<ip>"; // 全局变量,loadrunner数据参数化会失败。必须放到下面局部变量public int action() throws Throwable {这里面参数化}
String userName = "root";
String password = "12345";
String shell = "mkdir tangxje";
*/ public void startPython(String hostname,String username,String password,String shell)throws Exception{ try
{
Connection conn = new Connection(hostname);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
Session sess = conn.openSession();
sess.execCommand(shell); System.out.println("ExitCode: " + sess.getExitStatus());
sess.close();
conn.close();
}
catch (IOException e)
{
e.printStackTrace(System.err);
System.exit(2);
} } public int init() throws Throwable {
return 0;
}//end of init public int action() throws Throwable { String server = "<ip>";
String userName = "root";
String password = "12345";
String shell = "mkdir tangxje"; startPython(server, userName, password, shell); return 0;
}//end of action public int end() throws Throwable {
return 0;
}//end of end
}

D:\TestCase\20170703_docker_rongqiyun\tc_docker_ssh_docker_push\ip.dat

 ip
10.19.95.19

end