Accessing linux server from java program and run TCL scripts stored on the linux server -


i know kind of specific , need find answers dividing question in sub-questions. want know optimal way same.

i have linux server have own login. there tcl scripts stored on linux server. want write java program invoking windows machine, should connect linux server once provide login name, password , hostname , should execute scripts directory scripts stored.

what tried (found on net) below. way takes lot of time connect , execute simple commands "ls". running scripts, need set environment variables able set not able execute script after gave execute permission on it.

static string executecommand(session session, string command)              throws exception {         channelexec channel = (channelexec) session.openchannel("exec");         channel.setcommand(command);         channel.setinputstream(null);         channel.seterrstream(system.err);         channel.connect();          inputstream in = channel.getinputstream();          bufferedreader br = new bufferedreader(new inputstreamreader(in));         string line;         stringbuffer sb = new stringbuffer();         while ((line = br.readline()) != null) {                 sb.append(line + '\n');         }         channel.disconnect();          return sb.tostring();     }  private void jbutton1mouseclicked(java.awt.event.mouseevent evt) {                                           // todo add handling code here:      try {                 jsch jsch = new jsch();                 system.out.println("logging in");              session session = jsch.getsession("login name", "host name", port);              session.setpassword("password");                  java.util.properties config = new java.util.properties();             config.put("stricthostkeychecking", "no");             session.setconfig(config);              session.connect();             system.out.println("logged in");              system.out.println("==>" + executecommand(session, "ls"));          //system.out.println("==>" + executecommand(session, "./first"));                 thread.sleep(60000);              session.disconnect();                 system.out.println("disconnected");           } catch (exception e) {             e.printstacktrace();         }  }  

the shell script "first" has below line

echo "first script" sh testscripts/assignment1.scr 

while same script if run ssh terminal desired output , tcl script runs correctly. if try run program not able run , gives error

 testscripts/assignment1.scr: line 3: /bin/tclsh: no such file or directory testscripts/assignment1.scr: line 3: exec: /bin/tclsh: cannot execute: no such file or directory 


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -