summaryrefslogtreecommitdiffstats
path: root/Dozentenmodul/src/Jsch
diff options
context:
space:
mode:
authortspitzer2013-09-17 15:38:08 +0200
committertspitzer2013-09-17 15:38:08 +0200
commit205f059ec5df1a24daa87f8563d2bbb99344ecf9 (patch)
tree4f37a93f4224a5f37adb6e6477e65ce9e983febe /Dozentenmodul/src/Jsch
parentneue Version (diff)
downloadtutor-module-205f059ec5df1a24daa87f8563d2bbb99344ecf9.tar.gz
tutor-module-205f059ec5df1a24daa87f8563d2bbb99344ecf9.tar.xz
tutor-module-205f059ec5df1a24daa87f8563d2bbb99344ecf9.zip
g
Diffstat (limited to 'Dozentenmodul/src/Jsch')
-rw-r--r--Dozentenmodul/src/Jsch/scriptExecutor.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/Dozentenmodul/src/Jsch/scriptExecutor.java b/Dozentenmodul/src/Jsch/scriptExecutor.java
new file mode 100644
index 00000000..4d7b8f17
--- /dev/null
+++ b/Dozentenmodul/src/Jsch/scriptExecutor.java
@@ -0,0 +1,63 @@
+package Jsch;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
+import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+
+public class scriptExecutor {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ executeScript();
+ }
+
+ public static void executeScript()
+ {
+ JSch j=new JSch();
+
+ try {
+ Session se=j.getSession("root", "141.79.128.121", 22);
+
+ Properties config = new Properties();
+ config.setProperty("StrictHostKeyChecking", "no");
+ se.setConfig(config);
+ se.setPassword("!N4ye,04u.");
+ se.connect();
+ ChannelExec ch=(ChannelExec) se.openChannel("exec");
+ InputStream is=ch.getInputStream();
+
+ ch.setCommand("sh /home/openslx/hello.sh 'test'");
+ //ch.setCommand("ls");
+ ch.connect();
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ String line;
+ int index = 0;
+
+ while ((line = reader.readLine()) != null)
+ {
+ System.out.println(++index + " : " + line);
+ }
+
+ ch.disconnect();
+ se.disconnect();
+
+ System.out.println("Done!");
+ } catch (JSchException | IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}