From: Todd Holloway Date: 2002-07-04T06:37:30+09:00 Subject: Re: ruby and 8192 bytes thank you...that completes my first program! Now I'll go read about why it fixed it :) at some point I might make it more generic and not tied to certain IPs...but for now this works great. todd On Thu, Jul 04, 2002 at 06:32:05AM +0900, nobu.nokada@softhome.net wrote: > Hi, > > At Thu, 4 Jul 2002 05:27:00 +0900, > Todd Holloway wrote: > > I have tried just using the "system" commands by themselves > > and they seem to work just fine. I have also tried removing > > the "system" commands and the local file is not shortened > > to 8192 bytes. So, something is getting corrupted in between. > > Put $defout.flush (or $defout.close) before "system" commands. > > -- > Nobu Nakada for those who care, #!/usr/local/bin/ruby -w # this Ruby program takes the /etc/sysconfig/iptables from "machine1" # and creates an appropriate one for "machine2" # adds File.["compare", "move", "safe_unlink", "o_chmod", "mv", # "makedirs", "cp", "cmp", "mkpath", "syscopy", "rm_f", # "copy", "install", "catname"] require 'ftools' # ## in-line editting w/o a backup copy $-i = "" # ## Change current working Dir.chdir("/etc/sysconfig") # begin # copy iptables to iptables4machine2 and report any errors File.copy("iptables","iptables4machine2",true) rescue SystemCallError $stderr.print "Copy failed: " + $! + "\n" raise end # Replace any command line arguments with iptables4machine2 begin # Replace any command line arguments with iptables4machine2 ARGV.replace(['iptables4machine2']) while line = gets next if /^\s*#/ =~ line next if /^\s*$/ =~ line # perform substitution in place # changes "machine1" external IP address "machine2" line.gsub!(/10.1.0.1/,'10.1.0.2') # changes "machine1" internal IP address "machine2" line.gsub!(/192.168.1.1/,'192.168.1.2') print line.gsub(/-A INPUT -s 192.168.1.2 -p icmp -m state --state NEW/, '-A INPUT -s 192.168.1.1 -p icmp -m state --state NEW') end rescue SystemCallError $stderr.print "Something failed: " + $! + "\n" File.delete("iptables4machine2") raise end $defout.flush system("ssh machine2 cp /etc/sysconfig/iptables /etc/sysconfig/iptables.orig") system("scp iptables4machine2 machine2:/etc/sysconfig/iptables") system("ssh machine2 /etc/init.d/iptables stop") system("ssh machine2 /etc/init.d/iptables start") todd