ip.txt
10.199.198.1 10.199.198.2 10.199.198.3Error:
update Hosts set `TM-Me`=0 where IP="10.199.198.1 "; update Hosts set `TM-Me`=0 where IP="10.199.198.2 "; update Hosts set `TM-Me`=0 where IP="10.199.198.3 ";The SQL-statement should be:
update Hosts set `TM-Me`=0 where IP="10.199.198.1"; update Hosts set `TM-Me`=0 where IP="10.199.198.2"; update Hosts set `TM-Me`=0 where IP="10.199.198.3";The Rubyscript:
#!/usr/bin/ruby -w require "mysql" begin dbh = Mysql.real_connect("10.199.198.5", "root", "cisco", "hostlist") f = open("C:\\Users\\Lars\\Desktop\\ip.txt") ip_array = [] f.each_line { |line| ip_array << line } index = 0 until index == ip_array.length dbh.query ("update Hosts set `TM-Me`=0 where IP=\"#{ip_array[index]}\";\n") printf ("update Hosts set `TM-Me`=0 where IP=\"#{ip_array[index]}\";\n") index += 1 end f.close ensure dbh.close if dbh end