SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Wednesday, November 26, 2008

Module Etc

The etc module provides access to information from the /etc/passwd and /etc/group files on Linux and Unix systems.

Methods available in the module are

  1. endgrent
  2. endpwent
  3. getgrent
  4. getgrgid
  5. getgrnam
  6. getlogin
  7. getpwent
  8. getpwnam
  9. getpwuid
  10. group
  11. passwd
  12. setgrent
  13. setpwent



1.endgrent()


Ends the process of scanning through the /etc/group file begun by getgrent, and closes the file.


irb(main):032:0* require 'etc'
=> true
irb(main):033:0> Etc.endgrent
=> nil
irb(main):034:0> Etc.endpwent
=> nil
irb(main):035:0> Etc.getgrent
=> #
irb(main):036:0> Etc.getgrgid(1)
=> #
irb(main):037:0> Etc.getgrnam('root')
=> #
irb(main):038:0> Etc.getgrnam('users')
=> #
irb(main):039:0> Etc.getlogin
=> "gen"
irb(main):040:0> Etc.getpwent
=> #
irb(main):041:0> Etc.getpwnam('root')
=> #
irb(main):042:0> Etc.getpwuid(3)
=> #
irb(main):043:0> Etc.group{|g| puts g.name}
root
daemon
bin
sys
adm
tty
disk
lp
mail
news
uucp
man
proxy
kmem
dialout
fax
voice
cdrom
floppy
tape
sudo
audio
dip
www-data
backup
operator
list
irc
src
gnats
shadow
utmp
video
sasl
plugdev
staff
games
users
nogroup
libuuid
dhcp
syslog
klog
scanner
nvram
fuse
ssl-cert
lpadmin
crontab
mlocate
ssh
avahi-autoipd
gdm
admin
pulse
pulse-access
pulse-rt
messagebus
avahi
netdev
polkituser
haldaemon
gen
mysql
=> #
irb(main):044:0> Etc.passwd{|u| puts u.name}
root
daemon
bin
sys
sync
games
man
lp
mail
news
uucp
proxy
www-data
backup
list
irc
gnats
nobody
libuuid
dhcp
syslog
klog
hplip
avahi-autoipd
gdm
pulse
messagebus
avahi
polkituser
haldaemon
gen
sshd
mysql
=> #
irb(main):045:0> Etc.setgrent
=> nil
irb(main):046:0> Etc.setpwent
=> nil
irb(main):047:0>