Connecting two unix server's and push data from server to server using java program -
i have create java program connect unix server1 (with user name pwd),now need connect server (with username password) , execute command push data server 1 server 2 using java program.
server1 connection working fine , can execute basic commands in it.
code below
import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception; import java.io.inputstream; import java.text.dateformat; import java.text.parseexception; import java.text.simpledateformat; import java.util.arraylist; import java.util.date; import java.util.hashmap; import java.util.properties; import net.neoremind.sshxcute.core.connbean; import net.neoremind.sshxcute.core.result; import net.neoremind.sshxcute.core.sshexec; import net.neoremind.sshxcute.exception.taskexecfailexception; import net.neoremind.sshxcute.task.customtask; import net.neoremind.sshxcute.task.impl.execcommand; public class unixconnect { // string hostname, string logfile, string username, string password static string[] host_names = null; static string[] user_names = null; static string[] pwd_text = null; public void execcommand() throws taskexecfailexception { connbean cb1 = new connbean("0.000.00.000", "***", "****"); sshexec ssh1 = sshexec.getinstance(cb1); ssh1.connect(); string[] cmd = {"cd /apps/a/b/c/logs","tail -1 aloadjob.log"}; customtask tasks = new execcommand(cmd); result res1 = ssh1.exec(tasks); if (res1.issuccess) { /*system.out.println(res1.sysout)*/; } else { system.out.println("return code: " + res1.sysout); system.out.println("error message: " + res1.error_msg); } ssh1.disconnect(); } /** * @param args */ public static void main(string[] args) throws taskexecfailexception { unixconnect ob = new unixconnect(); ob.execcommand(); }
}
in both server need give username , password
this bit strange use case following:
implement bash script on server1 job of transfering data server2. of course server1 has able connecto server2
use program invoke bash script on server1.
Comments
Post a Comment