#!/usr/bin/ruby #serverhw : reports a server's hardware specs in English. # Takes no arguments, operates on local host. Linux only. Uses '/proc' # # DD: #(08:08:58 PM) billadric jabber orgjabber.natnet.com: You say "server is a dual processor xeon #2.8 with 2 GIGS of RAM and 2x120 RAID" or whatever it is. Disk space issues #say "you have 120 gigs available of which you have used 119 gigs" or whatever #it may be #check for args, display usage for ? or the like def get_args if ARGV.length > 0 puts "Usage: ruby serverhw.rb" exit end end #Scrape data about processor(s) from /proc into a hash adric jabber orgcpus. def get_cpus #get /proc data in, squash out lines that are the same @cpuinfo = File.open('/proc/cpuinfo').readlines.uniq #get modelname line and drop the newline @modelname = @cpuinfo.find {|line| line =~ /^model name/ }.chop #get model string @model = /(^model name\t: )(.*)/.match(@modelname)[2] #hyperthreading? @ht = @cpuinfo.find {|line| line =~ /^flags/}.include?(' ht ') #cpu count?? adric jabber orgcpus = {} end #Get total RAM (from now) into a hash adric jabber orgmemory. Uses free(1) def get_memory #stub adric jabber orgmemory = {} end #disks: FIXME def get_disks end #output formatted string to console def output p '''#{adric jabber orghostname} has a #{adric jabber orgcpus['plural']} processor #{adric jabber orgcpus['vendor']} #{adric jabber orgcpus['model']} with #{adric jabber orgcpus['feature']} running at #{adric jabber orgcpus['GHz']}, #{adric jabber orgmemory['GBs']} gibibytes of RAM, and has disks.''' end #do stuff get_args # output #