質問編集履歴

2

確認方法

2016/01/19 07:25

投稿

javabigineer
javabigineer

スコア87

test CHANGED
File without changes
test CHANGED
@@ -113,3 +113,13 @@
113
113
  クーロンの設定
114
114
 
115
115
  00 16 * * * export LANG=ja_JP.UTF-8; bash $TEST_PATH/MainTest.sh 1>$TEST_PATH/cron.log 2>&1
116
+
117
+
118
+
119
+
120
+
121
+ 追記
122
+
123
+ cron.logにはエラーログは出力されていません。
124
+
125
+ 『「前のシェルが終了する前に次のシェルが開始され」ているというのはどのようにして確認されているのでしょうか。』→ 出力ログから、圧縮が終了する前に権限付与のシェルが流れていることを確認しました。

1

処理の記述\(抜粋\)とクーロン設定内容の記述

2016/01/19 07:25

投稿

javabigineer
javabigineer

スコア87

test CHANGED
File without changes
test CHANGED
@@ -7,3 +7,109 @@
7
7
  クーロンに登録すると、なぜこのような動作を起こすのでしょうか?
8
8
 
9
9
  また、そのようにならないようにするためにJavaから呼び出す際に記述しなければならないことはあるのでしょうか?(wait関数など?)
10
+
11
+
12
+
13
+ <Javaからシェルを呼び出している処理>
14
+
15
+ if(条件1){
16
+
17
+ command1 = "/bin/sh";
18
+
19
+ command2 = "圧縮シェルのフルパス";
20
+
21
+ command3 = "対象パス";
22
+
23
+ call(command1,command2,command3,);
24
+
25
+ }
26
+
27
+
28
+
29
+ if(条件2){
30
+
31
+ command1 = "/bin/sh";
32
+
33
+ command2 = "権限付与シェルのフルパス";
34
+
35
+ command3 = "対象パス";
36
+
37
+ call(command1,command2,command3,);
38
+
39
+ }
40
+
41
+
42
+
43
+
44
+
45
+ call(command1,command2,command3){
46
+
47
+ //command = 外部コマンド , args = 対象パス
48
+
49
+ ProcessBuilder pb = new ProcessBuilder(command1, command2,command3, args);
50
+
51
+ pb.redirectErrorStream(true); // 標準エラーを標準出力にマージする
52
+
53
+ // Processオブジェクト初期化
54
+
55
+ Process process = null;
56
+
57
+ // コマンドの実行
58
+
59
+ process = pb.start();
60
+
61
+ System.out.println("実行中");
62
+
63
+ // InputStreamの取得
64
+
65
+ stream = process.getInputStream();
66
+
67
+ while (stream.read() >= 0); // 標準出力のみ読み込む
68
+
69
+ process.waitFor();
70
+
71
+ if (process.exitValue() == 0) {
72
+
73
+ System.out.println("戻り値:" + process.exitValue() + "=コマンド正常終了");// 0なら正常終了
74
+
75
+ }
76
+
77
+ } catch (IOException e) {
78
+
79
+ e.printStackTrace();
80
+
81
+ throw new IJXException();
82
+
83
+ } catch (InterruptedException e) {
84
+
85
+ e.printStackTrace();
86
+
87
+ throw new IJXException();
88
+
89
+ } finally {
90
+
91
+ try {
92
+
93
+ // 標準出力ストリームクローズ
94
+
95
+ stream.close();
96
+
97
+ } catch (IOException e) {
98
+
99
+ e.printStackTrace();
100
+
101
+ throw new IJXException();
102
+
103
+ }
104
+
105
+ }
106
+
107
+ }
108
+
109
+
110
+
111
+
112
+
113
+ クーロンの設定
114
+
115
+ 00 16 * * * export LANG=ja_JP.UTF-8; bash $TEST_PATH/MainTest.sh 1>$TEST_PATH/cron.log 2>&1