Ver código fonte

脚本,输入输出

xueli.xue 9 anos atrás
pai
commit
b30fceb46d

+ 5 - 3
xxl-job-admin/src/main/webapp/WEB-INF/template/jobinfo/jobinfo.index.ftl Ver arquivo

192
 </textarea>
192
 </textarea>
193
 <textarea class="glueSource_shell" style="display:none;" >
193
 <textarea class="glueSource_shell" style="display:none;" >
194
 #!/bin/bash
194
 #!/bin/bash
195
-
196
 echo "xxl-job: hello shell"
195
 echo "xxl-job: hello shell"
197
 
196
 
198
-for item in 1 2 3
197
+echo "脚本位置:$0"
198
+echo "参数数量:$#"
199
+for param in $*
199
 do
200
 do
200
-    echo "shell : $item"
201
+    echo "参数 : $param"
201
     sleep 1s
202
     sleep 1s
202
 done
203
 done
203
 
204
 
204
 echo "Good bye!"
205
 echo "Good bye!"
206
+exit 0
205
 </textarea>
207
 </textarea>
206
 <textarea class="glueSource_python" style="display:none;" >
208
 <textarea class="glueSource_python" style="display:none;" >
207
 #!/usr/bin/python
209
 #!/usr/bin/python

+ 1 - 1
xxl-job-admin/src/main/webapp/static/js/jobinfo.index.1.js Ver arquivo

304
 	});
304
 	});
305
 
305
 
306
 
306
 
307
-    // GLUE模式开启
307
+    // 运行模式
308
     $(".glueType").change(function(){
308
     $(".glueType").change(function(){
309
 		// executorHandler
309
 		// executorHandler
310
         var $executorHandler = $(this).parents("form").find("input[name='executorHandler']");
310
         var $executorHandler = $(this).parents("form").find("input[name='executorHandler']");

+ 3 - 2
xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java Ver arquivo

48
         String logFileName = XxlJobFileAppender.filePath.concat(XxlJobFileAppender.contextHolder.get());
48
         String logFileName = XxlJobFileAppender.filePath.concat(XxlJobFileAppender.contextHolder.get());
49
 
49
 
50
         // invoke
50
         // invoke
51
-        ScriptUtil.execToFile(cmd, scriptFileName, logFileName);
52
-        return ReturnT.SUCCESS;
51
+        int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, params);
52
+        ReturnT<String> result = (exitValue==0)?ReturnT.SUCCESS:new ReturnT<String>(ReturnT.FAIL_CODE, "script exit value("+exitValue+") is failed");
53
+        return result;
53
     }
54
     }
54
 
55
 
55
 }
56
 }

+ 9 - 2
xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java Ver arquivo

65
      * @param command
65
      * @param command
66
      * @param scriptFile
66
      * @param scriptFile
67
      * @param logFile
67
      * @param logFile
68
+     * @param params
69
+     * @return
70
+     * @throws IOException
68
      */
71
      */
69
-    public static void execToFile(String command, String scriptFile, String logFile) throws IOException {
72
+    public static int execToFile(String command, String scriptFile, String logFile, String... params) throws IOException {
70
         // 标准输出:print (null if watchdog timeout)
73
         // 标准输出:print (null if watchdog timeout)
71
         // 错误输出:logging + 异常 (still exists if watchdog timeout)
74
         // 错误输出:logging + 异常 (still exists if watchdog timeout)
72
         // 标准输入
75
         // 标准输入
76
         // command
79
         // command
77
         CommandLine commandline = new CommandLine(command);
80
         CommandLine commandline = new CommandLine(command);
78
         commandline.addArgument(scriptFile);
81
         commandline.addArgument(scriptFile);
82
+        if (params!=null && params.length>0) {
83
+            commandline.addArguments(params);
84
+        }
79
 
85
 
80
         // exec
86
         // exec
81
         DefaultExecutor exec = new DefaultExecutor();
87
         DefaultExecutor exec = new DefaultExecutor();
82
         exec.setExitValues(null);
88
         exec.setExitValues(null);
83
         exec.setStreamHandler(streamHandler);
89
         exec.setStreamHandler(streamHandler);
84
-        int exitValue = exec.execute(commandline);
90
+        int exitValue = exec.execute(commandline);  // exit code: 0=success, 1/-1=fail
91
+        return exitValue;
85
     }
92
     }
86
 
93
 
87
 }
94
 }