netid-tools 0.3.10 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +16 -0
- data/VERSION +1 -1
- data/bin/ua_check +19 -22
- data/lib/netid-tools.rb +28 -25
- data/netid-tools.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -118,6 +118,18 @@ The NetID you want to check
|
|
118
118
|
|
119
119
|
Spits out various quota information, and highlights a line in red if a user is over quota. This writes directly to stdout.
|
120
120
|
|
121
|
+
## Netid#get_processes(host,user,system_user)
|
122
|
+
|
123
|
+
### What it does
|
124
|
+
|
125
|
+
Retrieves running processes for specified NetID
|
126
|
+
|
127
|
+
##Netid#check_webtype(user,system_user)
|
128
|
+
|
129
|
+
### What it does
|
130
|
+
|
131
|
+
Retrieves webtype(s) for specified NetID
|
132
|
+
|
121
133
|
### Method variables
|
122
134
|
|
123
135
|
#### user
|
@@ -131,6 +143,10 @@ The NetID you want to check
|
|
131
143
|
Version History
|
132
144
|
===============
|
133
145
|
|
146
|
+
## 0.3.10
|
147
|
+
|
148
|
+
* Add -p flag for full process check on hosts.
|
149
|
+
|
134
150
|
## 0.3.9
|
135
151
|
|
136
152
|
* Add webtype check to list of returned results in ua_check executable
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.11
|
data/bin/ua_check
CHANGED
@@ -8,41 +8,27 @@ options = {}
|
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: ua_check [options]"
|
10
10
|
|
11
|
-
|
12
11
|
opts.on("-c", "--concise", "Concise Results") do |c|
|
13
12
|
options[:concise] = c
|
14
13
|
end
|
15
14
|
opts.on("-d", "--debug", "Run in debug (verbosely)") do |d|
|
16
15
|
options[:debug] = d
|
17
16
|
end
|
17
|
+
opts.on("-p", "--processes", "View running processes on UA dev systems") do |p|
|
18
|
+
options[:processes] = p
|
19
|
+
end
|
18
20
|
end.parse!
|
19
21
|
|
20
|
-
# This is a simple script that will go through various hosts and check to see
|
21
|
-
# if a specified user is running MySQLd
|
22
|
-
#
|
23
|
-
# It assumes the user running the script has ssh keys setup for authentication
|
24
|
-
#
|
25
|
-
# Requires net-ssh gem and ruby compiled with openssl. Pulls SSH user from
|
26
|
-
# system's `whoami` command.
|
27
|
-
#
|
28
|
-
# Required: Ruby 1.9.2+
|
29
|
-
|
30
|
-
## To-Do:
|
31
|
-
# * Consolidate SSH connect lines
|
32
|
-
# * Grab owners/administrators?
|
33
|
-
|
34
|
-
|
35
|
-
# Set up initial variables
|
36
|
-
$results = 0
|
37
22
|
raise "No NetID(s) specified. Bailing." if ARGV.empty?
|
23
|
+
|
38
24
|
user = ARGV.map{|n| n.downcase}
|
39
25
|
user.each do |netid|
|
40
26
|
raise "#{netid} is not a valid NetID! Exiting." unless Netid.validate_netid?(netid)
|
41
27
|
end
|
42
|
-
|
28
|
+
|
43
29
|
system_user = `whoami`.chomp
|
44
30
|
system_hostname = `hostname`.chomp
|
45
|
-
|
31
|
+
|
46
32
|
hosts = [ "ovid01.u.washington.edu",
|
47
33
|
"ovid02.u.washington.edu",
|
48
34
|
"ovid03.u.washington.edu",
|
@@ -73,8 +59,19 @@ user.each do |netid|
|
|
73
59
|
puts "Webtypes set: #{Netid.check_webtype(netid, system_user)}"
|
74
60
|
|
75
61
|
puts "No MySQLds Detected".bold.blue if results == 0
|
76
|
-
|
77
|
-
|
62
|
+
|
63
|
+
if options[:processes]
|
64
|
+
hosts.each do |host|
|
65
|
+
processes = Netid.get_processes(host,netid,system_user)
|
66
|
+
if processes
|
67
|
+
puts "\nProcesses for #{host}:\n".cyan
|
68
|
+
processes.each do |l|
|
69
|
+
puts l
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
78
75
|
unless options[:concise]
|
79
76
|
puts "\n"
|
80
77
|
Netid.quota_check(netid,system_user)
|
data/lib/netid-tools.rb
CHANGED
@@ -2,8 +2,6 @@ require 'net/ssh'
|
|
2
2
|
require 'colored'
|
3
3
|
|
4
4
|
class Netid
|
5
|
-
# Validate that string is in the form of a valid NetID. eg: 1-8 chars, doesn't start
|
6
|
-
# with a number, and no special characters
|
7
5
|
def self.validate_netid?(netid)
|
8
6
|
if netid.to_s.length > 8 || netid !~ /^[a-zA-Z][\w-]{0,7}$/
|
9
7
|
false
|
@@ -12,8 +10,6 @@ class Netid
|
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
|
-
# Checks to see if MySQL is running on a specified host. Returns array with host, port
|
16
|
-
# if present, returns false if not present.
|
17
13
|
def self.check_for_mysql_presence(host,user,system_user)
|
18
14
|
Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
|
19
15
|
output = ssh.exec!("ps -U #{user} -u #{user} u")
|
@@ -26,7 +22,22 @@ class Netid
|
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
29
|
-
|
25
|
+
def self.get_processes(host,user,system_user)
|
26
|
+
output = ""
|
27
|
+
Net::SSH.start(host,system_user,{auth_methods: %w(publickey)}) do |ssh|
|
28
|
+
if /no such user/i =~ ssh.exec!("id #{user}")
|
29
|
+
output = nil
|
30
|
+
else
|
31
|
+
output = ssh.exec!("ps -f --user=#{user}").lines
|
32
|
+
end
|
33
|
+
end
|
34
|
+
if output.nil? || output.count == 1
|
35
|
+
false
|
36
|
+
else
|
37
|
+
output
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
30
41
|
def self.check_for_localhome(user,system_user)
|
31
42
|
host = 'ovid02.u.washington.edu'
|
32
43
|
Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
|
@@ -35,40 +46,32 @@ class Netid
|
|
35
46
|
false
|
36
47
|
else
|
37
48
|
output.chomp
|
38
|
-
|
39
|
-
|
40
|
-
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
41
52
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
53
|
+
def self.check_webtype(user,system_user)
|
54
|
+
host = 'ovid02.u.washington.edu'
|
55
|
+
Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
|
56
|
+
ssh.exec!("webtype -user #{user}").chomp
|
47
57
|
end
|
58
|
+
end
|
48
59
|
|
49
60
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# Split along newlines
|
61
|
+
def self.quota_check(user,system_user)
|
62
|
+
host = 'ovid02.u.washington.edu'
|
63
|
+
Net::SSH.start(host,system_user, {auth_methods: %w( publickey )}) do |ssh|
|
64
|
+
result = ssh.exec!("quota #{user}").chomp
|
55
65
|
result = result.split("\n")
|
56
|
-
# This deletes the first blank line. There be an easier way to do this
|
57
66
|
result.delete_at(0) if result.first == ''
|
58
|
-
# Go through each line of the result
|
59
67
|
result.each_with_index do |line,index|
|
60
|
-
# The first two are headers: print and ignore
|
61
68
|
if index == 0 || index == 1
|
62
69
|
puts line
|
63
70
|
next
|
64
71
|
end
|
65
|
-
# Break the line up into elements
|
66
72
|
line_components = line.squeeze(" ").split(" ")
|
67
|
-
# Check to see if usage is over quota
|
68
73
|
if line_components[1].to_f > line_components[2].to_f
|
69
74
|
puts "#{line.bold.red}"
|
70
|
-
# If there's a grace period, it shows up in [4], so we account for that
|
71
|
-
# and flag if its present
|
72
75
|
elsif line_components[4] =~ /day/i || line_components[4].to_i > line_components[5].to_i
|
73
76
|
puts line.bold.red+'\n'
|
74
77
|
else
|
data/netid-tools.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netid-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -204,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
204
204
|
version: '0'
|
205
205
|
segments:
|
206
206
|
- 0
|
207
|
-
hash: -
|
207
|
+
hash: -2234475979821287941
|
208
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
209
|
none: false
|
210
210
|
requirements:
|