2010-09-27 13:40:21 +02:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2010-09-29 13:33:50 +02:00
|
|
|
libexec = File.expand_path File.dirname( __FILE__)
|
|
|
|
machine, source, destination = ARGV[0...3]
|
2010-09-27 16:33:31 +02:00
|
|
|
|
2010-09-27 15:34:24 +02:00
|
|
|
class IO
|
|
|
|
def readall
|
|
|
|
buf = ''
|
|
|
|
loop do
|
|
|
|
buf << begin
|
|
|
|
self.sysread 4096
|
|
|
|
rescue EOFError
|
|
|
|
return buf
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class File
|
|
|
|
def self.readall file
|
|
|
|
open( file) {|f| f.readall }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-27 16:42:03 +02:00
|
|
|
class String
|
|
|
|
def shdump
|
|
|
|
"'#{gsub( /[\\']/, '\'\\\\\&\'')}'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-27 16:33:31 +02:00
|
|
|
$tor = tor = IO.pipe
|
|
|
|
$tos = tos = IO.pipe
|
2010-09-27 13:40:21 +02:00
|
|
|
|
2010-09-27 16:33:31 +02:00
|
|
|
if Process.fork
|
2010-09-27 13:40:21 +02:00
|
|
|
$stdin.reopen tor.first
|
2010-09-27 16:33:31 +02:00
|
|
|
tor.last.close
|
2010-09-27 13:40:21 +02:00
|
|
|
$stdout.reopen tos.last
|
2010-09-27 16:33:31 +02:00
|
|
|
tos.first.close
|
2010-09-29 14:11:18 +02:00
|
|
|
$stderr.puts( {:proc => 'c', :machine => machine, :source => source}.inspect)
|
2010-09-29 13:33:50 +02:00
|
|
|
exec 'ssh', machine, 'perl', '-e', File.readall( File.join( libexec, 's.pl')).shdump, source.shdump
|
2010-09-27 16:33:31 +02:00
|
|
|
else
|
|
|
|
$stdin.reopen tos.first
|
|
|
|
tos.last.close
|
|
|
|
$stdout.reopen tor.last
|
|
|
|
tor.first.close
|
2010-09-29 14:11:18 +02:00
|
|
|
$stderr.puts( {:proc => 'c', :exec => 'reciever', :destination => destination}.inspect)
|
2010-09-29 13:33:50 +02:00
|
|
|
exec 'perl', File.join( libexec, 'r.pl'), destination
|
2010-09-27 16:33:31 +02:00
|
|
|
end
|