nysol 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,402 @@
1
+ #!/usr/bin/env ruby
2
+ #/* ////////// LICENSE INFO ////////////////////
3
+ #
4
+ # * Copyright (C) 2013 by NYSOL CORPORATION
5
+ # *
6
+ # * Unless you have received this program directly from NYSOL pursuant
7
+ # * to the terms of a commercial license agreement with NYSOL, then
8
+ # * this program is licensed to you under the terms of the GNU Affero General
9
+ # * Public License (AGPL) as published by the Free Software Foundation,
10
+ # * either version 3 of the License, or (at your option) any later version.
11
+ # *
12
+ # * This program is distributed in the hope that it will be useful, but
13
+ # * WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF
14
+ # * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15
+ # *
16
+ # * Please refer to the AGPL (http://www.gnu.org/licenses/agpl-3.0.txt)
17
+ # * for more details.
18
+ #
19
+ # ////////// LICENSE INFO ////////////////////*/
20
+
21
+ module MCMD
22
+
23
+ require "rubygems"
24
+ require "nysol/mcsvin"
25
+
26
+ #= コマンドライン引数の型チェックと設定を扱うクラス
27
+ #
28
+ # コマンドライン引数は"key=value"、"-key"のいずれかの形式を想定している。
29
+ # Unix系OSの引数の標準形式とは異なることに注意する。
30
+ #
31
+ # チェック内容:
32
+ # 1. 指定可能な引数を指定し、それ以外の引数がコマンドラインで指定されればエラー終了(エラーをraise)する。
33
+ # 2. 必須の引数を指定し、コマンドラインで指定されていなければエラー終了させる。
34
+ # 3. 引数の型を設定し、型に応じた値チェック及び変換をおこなう。
35
+ #
36
+ # 扱える型:
37
+ # rubyの原始型として:
38
+ # 1.str: rubyのString型に変換: デフォルト値の指定
39
+ # 2.int: rubyのFixnum型に変換: デフォルト値の指定、有効な範囲チェック
40
+ # 3.float: rubyのFloat型に変換: デフォルト値の指定、有効な範囲チェック
41
+ # 4.bool: rubyのtrue/falseに変換: -key タイプのオプションが指定されたかどうかの真偽判定
42
+ # 特殊な型として:
43
+ # 5.file: rubyのString型に変換: ファイルのreadable or writableチェック
44
+ #
45
+ #=== 例1
46
+ # コマンドライン
47
+ # ------------------------------------------------------
48
+ # $ ruby test.rb v=0.2 -w
49
+ # ------------------------------------------------------
50
+ #
51
+ # test.rbの内容
52
+ # ------------------------------------------------------
53
+ # require 'nysol/mcmd'
54
+ # include MCMD
55
+ #
56
+ # args=Margs.new(ARGV)
57
+ # val = args.float("v=") # -> 0.2
58
+ # flag = args.bool("-w") # -> true
59
+ # ------------------------------------------------------
60
+ #
61
+ #=== 例2 引数存在チェックや型チェックの例
62
+ # コマンドライン
63
+ # ------------------------------------------------------
64
+ # $ ruby test.rb i=dat.csv v=value -abc
65
+ # ------------------------------------------------------
66
+ #
67
+ # test.rbの内容
68
+ # ------------------------------------------------------
69
+ # require 'nysol/mcmd'
70
+ # include MCMD
71
+ #
72
+ # # "i=,o=,w=,-flag,-x"以外の引数が指定されればエラー終了する。
73
+ # # "i=,w="引数を指定しなければエラー終了する。
74
+ # args=Margs.new(ARGV, "i=,o=,w=,-flag,-x", "i=,w=")
75
+ # iFileName = args.file("i=") # -> "dat.csv"
76
+ # oFileName = args.str("o=","result.csv") # -> "result.csv"
77
+ # weight = args.float("w=",0.1,0.0,1.0) # -> 0.1
78
+ # flag = args.bool("-abc") # -> true
79
+ # wFlag = args.bool("-w") # -> false
80
+ # ------------------------------------------------------
81
+ class Margs
82
+ attr_reader :argv
83
+ attr_reader :keyValue
84
+
85
+ #== コンストラクタ
86
+ # argv: rubyのARGV変数
87
+ #
88
+ # allKeyWords: key=もしくは-keyによる引数キーワードリスト(String Array)
89
+ # ここで指定した以外の引数がARGVに指定されていないことをチェックし、指定されていればエラー終了する。
90
+ # keyListを省略した場合はこのチェックをしない。
91
+ #
92
+ # mandatoryKeyWords: key=による引数キーワードリスト(String Array)
93
+ # ここで指定した引数がコマンドラインで指定されていなければエラー終了する。
94
+ # mandatoryKeyWordsを省略した場合はこのチェックをしない。
95
+ def initialize(argv, allKeyWords=nil, mandatoryKeyWords=nil, help_func=nil,ver_func=nil)
96
+ @argv=argv
97
+ @allKeyWords=allKeyWords
98
+ @mandatoryKeyWords=mandatoryKeyWords
99
+ @keyValue=Hash.new
100
+ @cmdName=$0.dup
101
+
102
+ # コマンドラインで指定された引数を一旦全てHashに格納する。
103
+ @argv.each{|arg|
104
+ if arg[0..0]=="-" then
105
+ @keyValue[arg]=true
106
+ begin
107
+ if arg=="--help"
108
+ if help_func
109
+ help_func()
110
+ exit()
111
+ else
112
+ help()
113
+ exit()
114
+ end
115
+ elsif arg=="--version"
116
+ if ver_func
117
+ ver_func()
118
+ exit()
119
+ else
120
+ ver_func()
121
+ exit()
122
+ end
123
+ end
124
+ rescue => err
125
+ # help関数がなければ通過させる。
126
+ break
127
+ end
128
+
129
+ else
130
+ pos=arg.index("=")
131
+ if pos==nil then
132
+ raise "invalid argument: `#{arg}'"
133
+ end
134
+ val=arg.split("=",2)[1] # 20140924 by ham
135
+ val="" if val==nil
136
+ @keyValue[arg[0..pos]]=val
137
+ end
138
+ }
139
+
140
+ # allKeyWordsのオプションタイプのキーワードを登録する
141
+ if @allKeyWords!=nil then
142
+ @allKeyWords.split(",").each{|kw|
143
+ if kw[0..0]=="-" and @keyValue[kw]==nil then
144
+ @keyValue[kw]=false
145
+ end
146
+ }
147
+ end
148
+
149
+ # 指定のキーワード以外のキーワードが指定されていないかチェック
150
+ if @allKeyWords!=nil then
151
+ kwList=@allKeyWords.split(",")
152
+ @keyValue.each{|kw,val|
153
+ if kwList.index(kw)==nil then
154
+ raise "I don't know such a argument: `#{kw}'"
155
+ end
156
+ }
157
+ end
158
+
159
+ # 必須引数のチェック
160
+ if @mandatoryKeyWords !=nil then
161
+ @mandatoryKeyWords.split(",").each{|kw|
162
+ if @keyValue[kw]==nil and kw[0..0]!="-" then
163
+ raise "argument `#{kw}' is mandatory"
164
+ end
165
+ }
166
+ end
167
+ end
168
+
169
+ public
170
+ #== String型引数の値のチェックと取得
171
+ # 返値: 引数で指定された値(String)
172
+ #
173
+ # key: "key="形式の引数キーワード(String)
174
+ # ここで指定した引数の値をStringとして返す。
175
+ # コマンドラインで指定されていなければdefaultの値を返す。
176
+ #
177
+ # default: コマンドラインで指定されなかったときのデフォルト値(String)
178
+ def str(key,default=nil,token1=nil,token2=nil)
179
+ val=@keyValue[key]
180
+ val=default if val==nil
181
+ if val!=nil then
182
+ if token1!=nil then
183
+ val=val.split(token1)
184
+ if token2!=nil then
185
+ ary=val.dup()
186
+ val=[]
187
+ ary.each{|v|
188
+ val << v.split(token2)
189
+ }
190
+ end
191
+ end
192
+ end
193
+ return val
194
+ end
195
+
196
+ #== Fixnum型引数の値のチェックと取得
197
+ # 返値: 引数で指定された値(Fixnum)
198
+ #
199
+ # key: "key="形式の引数キーワード
200
+ # ここで指定した引数の値をFloatとして返す。
201
+ # コマンドラインで指定されていなければdefaultの値を返す。
202
+ #
203
+ # default: コマンドラインで指定されなかったときのデフォルト値
204
+ #
205
+ # from: 値の下限値。指定した値が下限値を下回ればエラー終了する。
206
+ #
207
+ # to: 値の上限値。指定した値が上限値を上回ればエラー終了する。
208
+ def int(key, default=nil, from=nil, to=nil)
209
+ val=@keyValue[key]
210
+ val=default if val==nil
211
+
212
+ if val!=nil then
213
+ val=val.to_i
214
+ if from != nil and val<from then
215
+ raise "range error: `#{key}=#{val}': must be in [#{from}..#{to}]"
216
+ end
217
+ if to != nil and val>to then
218
+ raise "range error: `#{key}=#{val}': must be in [#{from}..#{to}]"
219
+ end
220
+ end
221
+
222
+ return val
223
+ end
224
+
225
+ #== Float型引数の値のチェックと取得
226
+ # 返値: 引数で指定された値(Float)
227
+ #
228
+ # key: "key="形式の引数キーワード
229
+ # ここで指定した引数の値をFloatとして返す。
230
+ # コマンドラインで指定されていなければdefaultの値を返す。
231
+ #
232
+ # default: コマンドラインで指定されなかったときのデフォルト値
233
+ #
234
+ # from: 値の下限値。指定した値が下限値を下回ればエラー終了する。
235
+ #
236
+ # to: 値の上限値。指定した値が上限値を上回ればエラー終了する。
237
+ def float(key, default=nil, from=nil, to=nil)
238
+ val=@keyValue[key]
239
+ val=default if val==nil
240
+
241
+ if val!=nil then
242
+ val=val.to_f
243
+ if from != nil and val<from then
244
+ raise "range error: `#{key}=#{val}': must be in [#{from}..#{to}]"
245
+ end
246
+ if to != nil and val>to then
247
+ raise "range error: `#{key}=#{val}': must be in [#{from}..#{to}]"
248
+ end
249
+ end
250
+
251
+ return val
252
+ end
253
+
254
+ #== Bool型引数の値のチェックと取得
255
+ # 返値: 引数で指定されたかどうか(true/false)
256
+ #
257
+ # key: "-key"形式の引数キーワード
258
+ # ここで指定した引数がコマンドラインで指定されていればtrueを、指定されていなければfalseを返す。
259
+ def bool(key)
260
+ return @keyValue[key]
261
+ end
262
+
263
+ #== ファイル型引数の値のチェックと取得
264
+ # 返値: 引数で指定されたファイル名(String)
265
+ #
266
+ # key: "key="形式の引数キーワード
267
+ # ここで指定した引数の値をファイル名と想定し、そのファイルがreadable(writable)かどうかをチェックする。
268
+ # readable(writable)であればそのファイル名を返し、readable(writable)でなければエラー終了する。
269
+ # readable(writable)チェックをしないのであればMargs::strを使えばよい。
270
+ #
271
+ # mode: "r"もしくは"w"を指定し、rならばreadableチェックを、wならwritebleチェックを行う。
272
+ def file(key,mode="r",default=nil)
273
+ val=@keyValue[key]
274
+ val=default if val==nil
275
+
276
+ if val!=nil then # valがnilの場合(ex. 値なし指定"i=")はノーチェックで通す
277
+ if mode=="r" then
278
+ if not File.readable? val then
279
+ raise "file open error: `#{val}' is not readable"
280
+ end
281
+ elsif mode=="w" then
282
+ if not File.writable? File.dirname(val) then
283
+ raise "file open error: `#{val}' is not writable"
284
+ end
285
+ end
286
+ end
287
+ return val
288
+ end
289
+
290
+ #== Field型引数の値のチェックと取得
291
+ # 返値: 各種配列のHash
292
+ # key=a1:b1%c1,a2:b2%c2,...
293
+ # names: [a1,a2,...]
294
+ # newNames: [b1,b2,...]
295
+ # flags: [c1,c2,...]
296
+ # fld2csv: a1,a2,...のCSVファイルにおける項目番号(0から始まる)
297
+ # csv2fld: CSVファイルの項目番号に対するa1,a2,...の番号(0から始まる)
298
+ def field(key,iFile,default=nil,min=nil,max=nil)
299
+ return unless iFile
300
+ val=@keyValue[key]
301
+ val=default if val==nil
302
+
303
+ names1=[]
304
+ names2=[]
305
+ flags=[]
306
+ fld2csv=[]
307
+ csv2fld=[]
308
+
309
+ # names1,names2,flagsの設定
310
+ if val!=nil then
311
+ val1=val.split(",")
312
+ val1.each{|v|
313
+ val2=v.split("%")
314
+ val3=val2[0].split(":")
315
+ names1 << val3[0]
316
+ names2 << val3[1]
317
+ flags << val2[1]
318
+ }
319
+
320
+ if min then
321
+ raise "#{key} takes at least #{min} field name(s)" if names1.size<min
322
+ end
323
+ if max then
324
+ raise "#{key} takes at most #{max} field name(s)" if names1.size>max
325
+ end
326
+
327
+ iNames=MCMD::Mcsvin.new("i=#{iFile}").names
328
+ # fld2csvの設定
329
+ (0...names1.size).each{|i|
330
+ pos=iNames.index(names1[i])
331
+ if pos==nil then
332
+ raise "field name not found: `#{names1[i]}'"
333
+ end
334
+ fld2csv << pos
335
+ }
336
+
337
+ # csv2fldの設定
338
+ (0...iNames.size).each{|i|
339
+ pos=fld2csv.index(i)
340
+ if pos!=nil
341
+ csv2fld << pos
342
+ else
343
+ csv2fld << nil
344
+ end
345
+ }
346
+
347
+ ret=Hash.new
348
+ ret["names"]=names1
349
+ ret["newNames"]=names2
350
+ ret["flags"]=flags
351
+ ret["fld2csv"]=fld2csv
352
+ ret["csv2fld"]=csv2fld
353
+ ret["csvNames"]=iNames
354
+ return ret
355
+ else
356
+ return nil
357
+ end
358
+ end
359
+
360
+ # key-valuを配列で返す
361
+ def getKeyValue(prefix=nil)
362
+ ret=[]
363
+ @keyValue.each{|k,v|
364
+ ret << ["#{prefix}#{k}","#{v}"]
365
+ }
366
+ return ret
367
+ end
368
+
369
+ # コマンドラインをkey-valuを配列で返す
370
+ def cmdline()
371
+ return "#{@cmdName} #{@argv.join(' ')}"
372
+ end
373
+
374
+ end # class
375
+ end # module
376
+
377
+ #==============================================
378
+ #以下、サンプルコード(require時は実行されない)
379
+ #==============================================
380
+ if __FILE__ == $0
381
+ include MCMD
382
+
383
+ # $ ruby ./margs.rb i=dat.csv v=value -abc
384
+ #args=Margs.new(ARGV, "i=,o=,w=,v=,-flag,-x,-abc", "i=,w=")
385
+ args=Margs.new(ARGV, "f=")
386
+ fld=args.field("f=","xxa")
387
+ exit
388
+ p fld["names"]
389
+ p fld["newNames"]
390
+ p fld["flags"]
391
+ p fld["fld2csv"]
392
+ p fld["csv2fld"]
393
+ exit
394
+ #p args.str("f=",",",":")
395
+ iFileName = args.file("i=") # -> "dat.csv"
396
+ oFileName = args.str("o=","result.csv") # -> "result.csv"
397
+ weight = args.float("w=",0.1,0.0,1.0) # -> 0.1
398
+ flag = args.bool("-abc") # -> true
399
+ wFlag = args.bool("-w") # -> false
400
+
401
+ end # サンプルコード
402
+ #==============================================
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ #/* ////////// LICENSE INFO ////////////////////
3
+ #
4
+ # * Copyright (C) 2013 by NYSOL CORPORATION
5
+ # *
6
+ # * Unless you have received this program directly from NYSOL pursuant
7
+ # * to the terms of a commercial license agreement with NYSOL, then
8
+ # * this program is licensed to you under the terms of the GNU Affero General
9
+ # * Public License (AGPL) as published by the Free Software Foundation,
10
+ # * either version 3 of the License, or (at your option) any later version.
11
+ # *
12
+ # * This program is distributed in the hope that it will be useful, but
13
+ # * WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF
14
+ # * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15
+ # *
16
+ # * Please refer to the AGPL (http://www.gnu.org/licenses/agpl-3.0.txt)
17
+ # * for more details.
18
+ #
19
+ # ////////// LICENSE INFO ////////////////////*/
20
+
21
+ #= MCMD ruby拡張ライブラリ
22
+ #Mコマンドruby拡張ライブラリとは、MCMDで提供されている各種データ処理モジュールをrubyから利用できるようにするインターフェースを提供する。
23
+ #
24
+ #mcmd.rbは、以下の6つのクラスライブラリをrequireしている。
25
+ # require "mcsvin" # MCMD::CSVin CSVの行単位読み込みクラス (c++で作成された共有ライブラリ)
26
+ # require "mcsvout" # MCMD::CSVout CSVの出力クラス (c++で作成された共有ライブラリ)
27
+ # require "mtable" # MCMD::Table CSVのメモリ展開クラス (c++で作成された共有ライブラリ)
28
+ # require "margs" # MCMD::Args コマンドライン引数を扱うクラス(rubyスクリプト)
29
+ # require "mtemp" # MCMD::Temp 一時ファイル管理(rubyスクリプト)
30
+
31
+ require "nysol/margs"
32
+ require "nysol/mutils"
33
+ require "nysol/mtemp"
34
+ require "nysol/mmethods"
35
+ require "nysol/mcsvin"
36
+ require "nysol/mcsvout"
37
+ require "nysol/mtable"
38
+ require "nysol/msysteminfo"
39
+ require "nysol/mnettools"
40
+ require "nysol/mparallel"
41
+ require "fileutils"
42
+
43
+
44
+
@@ -0,0 +1,220 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #/* ////////// LICENSE INFO ////////////////////
4
+ #
5
+ # * Copyright (C) 2013 by NYSOL CORPORATION
6
+ # *
7
+ # * Unless you have received this program directly from NYSOL pursuant
8
+ # * to the terms of a commercial license agreement with NYSOL, then
9
+ # * this program is licensed to you under the terms of the GNU Affero General
10
+ # * Public License (AGPL) as published by the Free Software Foundation,
11
+ # * either version 3 of the License, or (at your option) any later version.
12
+ # *
13
+ # * This program is distributed in the hope that it will be useful, but
14
+ # * WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF
15
+ # * NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16
+ # *
17
+ # * Please refer to the AGPL (http://www.gnu.org/licenses/agpl-3.0.txt)
18
+ # * for more details.
19
+ #
20
+ # ////////// LICENSE INFO ////////////////////*/
21
+ require 'rubygems'
22
+ require 'net/ftp'
23
+ require "nysol/mtemp"
24
+
25
+
26
+
27
+ module MCMD
28
+
29
+ module NetTools
30
+ @@ftpUse=true
31
+ @@retry_scp = 5
32
+ if File.exist?("/etc/nysol_netconf") then
33
+ File.open("/etc/nysol_netconf"){|fp|
34
+ while lin = fp.gets do
35
+ sp = lin.chomp!.split()
36
+ if sp[0] == "FtpUse" then
37
+ @@ftpUse=true if sp[1] == "true"
38
+ @@ftpUse=false if sp[1] == "falsed"
39
+ elsif sp[0] == "RetryTimes" then
40
+ @@retry_scp = sp[1].to_i if sp[1]
41
+ end
42
+ end
43
+ }
44
+ end
45
+
46
+ def self.config_info
47
+ puts "R #{@@retry_scp} F #{@@ftpUse}"
48
+ end
49
+
50
+ def self.cmdRun(ip,uid,cmd,secret=nil)
51
+ sts = false
52
+ @@retry_scp.times{|i|
53
+ if secret then
54
+ sts = system("ssh -i #{secret} #{uid}@#{ip} '#{cmd}'")
55
+ else
56
+ sts = system("ssh #{uid}@#{ip} '#{cmd}'")
57
+ end
58
+ break if sts
59
+ sleep 2**i
60
+ MCMD::warningLog("SSH CMDRUN RETRY(#{i+1}/#{@@retry_scp})")
61
+
62
+ }
63
+ MCMD::warningLog("ERROR by SSH ") unless sts
64
+ end
65
+
66
+ # バックグランド実行
67
+ def self.cmdRun_b(ip,uid,cmd,tag="" ,secret=nil)
68
+ sts = false
69
+ if secret then
70
+ sts = system("ssh -i #{secret} #{uid}@#{ip} 'nohup #{cmd}'")
71
+ else
72
+ sts = system("ssh #{uid}@#{ip} 'nohup #{cmd}'")
73
+ end
74
+ MCMD::warningLog("ERROR by SSH(nohub)") unless sts
75
+ end
76
+
77
+
78
+ #SCPファイル送信
79
+ def self.scp(ip,uid,from,to,secret=nil)
80
+ sts =false
81
+ unless File.file?(from) then
82
+ raise "File not found."
83
+ end
84
+ if to =~ /\/$/ then
85
+ cmdRun(ip,uid,"mkdir -p #{to}",secret)
86
+ else
87
+ cmdRun(ip,uid,"mkdir -p #{File.dirname(to)}",secret)
88
+ end
89
+ if secret then
90
+ @@retry_scp.times{|i|
91
+ sts = system("scp -i #{secret} -C #{from} #{uid}@#{ip}:#{to}")
92
+ break if sts
93
+ sleep 2**i
94
+ MCMD::warningLog("SCP SEND RETRY(#{i+1}/#{@@retry_scp})")
95
+ }
96
+ else
97
+ @@retry_scp.times{|i|
98
+ sts = system("scp -C #{from} #{uid}@#{ip}:#{to}")
99
+ break if sts
100
+ sleep 2**i
101
+ MCMD::warningLog("SCP SEND RETRY(#{i+1}/#{@@retry_scp})")
102
+ }
103
+ end
104
+ MCMD::warningLog("send ERROR by scp") unless sts
105
+ end
106
+
107
+
108
+ #Ftpファイル送信
109
+ def self.ftp(ip,uid,from,to,secret)
110
+ sts =false
111
+ unless File.file?(from) then
112
+ raise "File #{from} not found. "
113
+ end
114
+ if to =~ /\/$/ then
115
+ cmdRun(ip,uid,"mkdir -p #{to}")
116
+ else
117
+ cmdRun(ip,uid,"mkdir -p #{File.dirname(to)}")
118
+ end
119
+ temp=MCMD::Mtemp.new
120
+ fn = temp.file
121
+ File.open("#{fn}","w"){|fw|
122
+ fw.puts "open #{ip}"
123
+ fw.puts "user #{uid} #{secret}"
124
+ fw.puts "prompt"
125
+ fw.puts "bi"
126
+ fw.puts "put #{from} #{to}"
127
+ fw.puts "bye"
128
+ }
129
+
130
+ @@retry_scp.times{
131
+ sts = system("ftp -n < #{fn} > /dev/null")
132
+ #sts = system("ftp -n < #{fn} ")
133
+ break if sts
134
+ sleep 2**i
135
+ MCMD::warningLog("FTP SEND RETRY(#{i+1}/#{@@retry_scp})")
136
+ }
137
+ MCMD::warningLog("send ERROR by ftp") unless sts
138
+ end
139
+
140
+ def self.send(ip,uid,from,to,secret)
141
+ if @@ftpUse then
142
+ ftp(ip,uid,from,to,secret)
143
+ else
144
+ scp(ip,uid,from,to)
145
+ end
146
+ end
147
+
148
+
149
+
150
+
151
+
152
+ #SCPファイル受信
153
+ def self.scp_r(ip,uid,from,to,secret=nil)
154
+ if to =~ /\/$/ then
155
+ system("mkdir -p #{to}")
156
+ else
157
+ system("mkdir -p #{File.dirname(to)}")
158
+ end
159
+ from.each{|fn|
160
+ if secret then
161
+ system("scp -i #{secret} -C #{uid}@#{ip}:#{fn} #{to}> /dev/null")
162
+ else
163
+ system("scp -C #{uid}@#{ip}:#{fn} #{to} > /dev/null")
164
+ end
165
+ }
166
+ end
167
+
168
+ #ftpファイル受信
169
+ #
170
+ #MCMD::NetTools.ftp_r(ip,pcinfo[ip][0],path.addSuffix("/#{fn[i]}"),dicName,pcinfo[ip][1])
171
+
172
+ def self.ftp_r(ip,uid,from,to,secret)
173
+ tod = to
174
+ if to =~ /\/$/ then
175
+ system("mkdir -p #{to}")
176
+ else
177
+ system("mkdir -p #{File.dirname(to)}")
178
+ tod = File.dirname(to)
179
+ end
180
+ temp=MCMD::Mtemp.new
181
+ fn = temp.file
182
+ File.open("#{fn}","w"){|fw|
183
+ fw.puts "open #{ip}"
184
+ fw.puts "user #{uid} #{secret}"
185
+ fw.puts "prompt"
186
+ fw.puts "lcd #{tod}"
187
+ fw.puts "bi"
188
+ from.each{|fr|
189
+ fw.puts "cd #{File.dirname(fr)}"
190
+ fw.puts "mget #{File.basename(fr)}"
191
+ }
192
+ fw.puts "bye"
193
+ }
194
+ @@retry_scp.times{|i|
195
+ sts = system("ftp -n < #{fn} > /dev/null")
196
+ break if sts
197
+ sleep 2**i
198
+ MCMD::warningLog("FTP RECV RETRY(#{i+1}/#{@@retry_scp})")
199
+ }
200
+ end
201
+
202
+ def self.recv(ip,uid,from,to,secret)
203
+ if @@ftpUse then
204
+ ftp_r(ip,uid,from,to,secret)
205
+ else
206
+ scp_r(ip,uid,from,to)
207
+ end
208
+ end
209
+
210
+
211
+ end
212
+ end
213
+
214
+
215
+ if __FILE__ == $0 then
216
+
217
+ MCMD::NetTools.scp("192.168.4.212","nysol","mtemp.rb","/tmp/xxxa")
218
+ MCMD::NetTools.cmdRun("192.168.4.212","nysol","cd /tmp; ls -l xxxa")
219
+
220
+ end