升级列表自动生成脚本-创新互联
一个自动生成升级文件列表的脚本,可以运行在WIN或者linux

要判断中间的版本号,取大的
文件最终样式如下
productname:ABCikn7
version:2.23.81
uname:ABCikn7_2.23.81_20120101.upt
usize:3598290
dname:ABCikn7_2.23.81_20120101.dd5
dsize:33
url1:ftp://ftp.163.com/down/
productname:xx001A
version:4.0.4
uname:xx001A_4.0.4_20131114.upt
usize:14008320
dname:xx001A_4.0.4_20131114.dd5
dsize:40
url1:ftp://ftp.163.com/down/
url2:ftp://ftp.265.com/down/
#!/usr/bin/ruby
require 'net/ftp'
ip = ["1.2.3.4","2.11.12.2"] #server IP add
url = ["url1:ftp://ftp.163.com/down/","url2:ftp://ftp.265.com/down/"]
update_file = ["e:\\update.txt", "/tmp/update.dat"] #Win or Linux
file_hash = {}
text = ''
def os_family
case RUBY_PLATFORM
when /ix/i, /ux/i, /gnu/i,
/sysv/i, /solaris/i,
/sunos/i, /bsd/i
"unix"
when /win/i, /ming/i
"windows"
else
"other"
end
end
if os_family == "unix"
text_file = update_file[1]
elsif os_family == "windows"
text_file = update_file[0]
else puts "unkown os"
Process.exit(1)
end
def file_list(ip)
#get ftp dir list
files = []
ip.size.times{|x|
ftp = Net::FTP.open(ip[x])
ftp.login('username','password')
ftp.passive = true
files << ftp.list('down')
ftp.close
}
return files
end
def key_values(type,n,name_size) #get type_x.x.x_date.upt
dd, up = '', ''
if n == 1
regexp = "#{type}_\\d+\\.\\d+\\.\\d+_\\d+."
else
regexp = "#{type}_\\d+\\."
end
2.times {
name_size.each_key { |m|
if /#{regexp}dd5/.match(m)
dd = m.to_s
elsif /#{regexp}upt/.match(m)
up = m.to_s
end
}
}
return dd, name_size[dd], up, name_size[up]
end
def formatstr(dd,dd_size,up,up_size)
type, ver = '', ''
tmp = []
tmp = dd.split('_')
type = tmp[0]
ver = tmp[1]
msg =<创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
当前文章:升级列表自动生成脚本-创新互联
文章路径:http://www.jxjierui.cn/article/dshocp.html


咨询
建站咨询
