-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetOSStemps
More file actions
executable file
·65 lines (59 loc) · 1.45 KB
/
getOSStemps
File metadata and controls
executable file
·65 lines (59 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/ruby
require 'socket'
require 'timeout'
require '/mmt/admin/srv/tcs_lookup.rb'
# Reads from a crate or mini-server via a socket connection.
def read_service(service)
vals = Hash.new
host, port = srv_lookup(service)
sock = sockopen(host, port)
if sock
sock.puts("all")
loop {
rtn_val = sock.gets
# Can get an error on stripping if you don't check for NilClass first.
break unless rtn_val
# This is the normal exit, i.e., ".EOF" read at end of data.
next if rtn_val == ".EOF"
rtn_val = rtn_val.strip
rtn_val =~ /(\w+)\s+(.*)/
if $1 and $2
vals[$1] = $2
else
break
end
}
end
sock.close() if sock
sock = nil
return vals
end
# open a socket
def sockopen(host, port)
socket = nil
status = nil
begin
timeout(1) {
socket = TCPSocket.open(host, port)
}
rescue Timeout::Error
status = "Timeout"
return nil
rescue Errno::ECONNREFUSED
status = "Refusing connection"
return nil
rescue => why
status = "Error: #{why}"
return nil
end
return socket
end
oss1 = read_service('temptrax')
oss2 = read_service('temptrax3')
oss_nw_top = oss2['temptrax3_probe10']
oss_sw_top = oss2['temptrax3_probe11']
oss_ne_top = oss1['temptrax_probe2']
oss_se_top = oss1['temptrax_probe3']
oss_sw_bot = oss2['temptrax3_probe12']
oss_se_bot = oss1['temptrax_probe4']
print "#{oss_nw_top} #{oss_ne_top} #{oss_sw_top} #{oss_se_top} #{oss_sw_bot} #{oss_se_bot}"