Created
April 15, 2010 00:53
-
-
Save sms420/366556 to your computer and use it in GitHub Desktop.
groupFile.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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