Skip to content

Instantly share code, notes, and snippets.

@sms420
Created April 15, 2010 00:53
Show Gist options
  • Select an option

  • Save sms420/366556 to your computer and use it in GitHub Desktop.

Select an option

Save sms420/366556 to your computer and use it in GitHub Desktop.
groupFile.rb
#!/usr//bin/env ruby
# groupFile.rb
# Sean Stephenson
# parses /etc/group file
/******************* getGroupFile *********************/
def getGroupFile
groupFile = `/usr/local/bin/rcopy.rb -q -r /etc/group`
return true if groupFile == ""
return false
end
/******************* isCRN?(checkNumber) *********************/
def isCRN?(checkNumber)
if checkNumber =~ /^\d{5}$/
return true
else
return false
end
end
/******************* getCRNFromGroupFile(crn) *********************/
def getCRNFromGroupFile(crn)
begin
file = File.open("group","r")
rescue
puts "no group file"
return
end
matchedLine = ""
while(line = file.gets)
matchedLine = line if line =~ /^c#{crn}/
end
file.close
return matchedLine
end
/******************* createUserArray(line) *********************/
def createUserArray(line)
#sample input: c38960::1234:user1,user2,user3
users = line.match(/(^c.*:)(.*$)/)[2].split(',') if line != nil
return users
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment