Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a python script called groups that makes a report about all of the groups

ID: 645099 • Letter: W

Question

Write a python script called groups that makes a report about all of the groups that each user on the system belongs to, as specified by passwd and group files. The location of these two files should be gotten through interactive input with the user.

The report your script generates should contain one line for every user in the passwd file. Write a python script called groups that makes a report about all of the groups that each user on the system belongs to, as specified by passwd and group files. The location of these two files should be gotten through interactive input with the user.

The report your script generates should contain one line for every user in the passwd file. Each output line should contain the user name, the name of the primary group (this is the group that matches up to the GID field in the passwd file entry), and a comma separated list of any other groups beyond that to which the user belongs, listed in alphabetical order. Thus a line of output for a user might look something like:

User: root Primary: root Secondary: adm, bin, daemon, disk, floppy, sys, wheel

Thus a line of output for a user might look something like:

User: root Primary: root Secondary: adm, bin, daemon, disk, floppy, sys, wheel

Upload your script file, as well as the output generated for the sample passwd and group files below

GroupFile:

root::0:root,eggert,sync,shutdown,halt,operator

bin::1:root,bin,daemon

daemon::2:root,bin,daemon

sys::3:root,bin,adm

adm::4:root,adm,daemon

tty::5:

disk::6:root,adm

lp::7:lp

mem::8:

kmem::9:

wheel::10:root

floppy::11:root

mail::12:mail,postmaster

news::13:news

uucp::14:uucp

man::15:man

users::100:games,nobody,guest,moebusmg,cs330s10,gibbon,baliane,eggert

faculty::200:eggert,barun,alice,csdept

students::300:

misc::400:ftp,ppp

nogroup::-2:

smmsp::500:smmsp

eggert::600:eggert

PASSWORDFILE :

root:EXZN9rGUxvs5I:0:0:root:/root:/bin/tcsh

bin:*:1:1:bin:/bin:

daemon:*:2:2:daemon:/sbin:

adm:*:3:4:adm:/var/adm:

lp:*:4:7:lp:/var/spool/lpd:

sync:*:5:0:sync:/sbin:/bin/sync

shutdown:*:6:0:shutdown:/sbin:/sbin/shutdown

halt:*:7:0:halt:/sbin:/sbin/halt

mail:*:8:12:mail:/var/spool/mail:

news:*:9:13:news:/usr/lib/news:

uucp:*:10:14:uucp:/var/spool/uucppublic:

operator:*:11:0:operator:/root:/bin/bash

games:*:12:100:games:/usr/games:

man:*:13:15:man:/usr/man:

postmaster:*:14:12:postmaster:/var/spool/mail:/bin/bash

nobody:*:65534:100:nobody:/dev/null:

ftp:*:400:400:Anonymous FTP:/home/doghouse/services/ftp:/bin/true

guest:*:405:100:guest:/dev/null:/dev/null

eggert:EoI04KCYXrbGc:501:200:David W. Eggert:/home/doghouse/faculty/eggert:/bin/tcsh

barun:oRNOJBcY6lU6Y:502:200:Barun Chandra:/home/doghouse/faculty/barun:/bin/tcsh

csdept:aTRIlmgw9OMAc:503:200:Technician account:/home/doghouse/faculty/csdept:/bin/tcsh

alice:8UE/siivOcFAA:504:200:Alice Fischer:/home/doghouse/faculty/alice:/bin/tcsh

moebusmg:8dIRFibt5Ig2k:505:100:Martin Moebus:/home/doghouse/faculty/moebusmg:/bin/tcsh

cs330s10:UuyfGjRFaXed.:515:100:CS 330 Student 10:/home/doghouse/students/cs330s10:/bin/tcsh

ppp:k05GCpJWatxZY:519:400:PPP client login:/home/doghouse/services/ppp:/usr/sbin/pppd proxyarp

smmsp:*:506:500:Sendmail user:/sbin:

ggibson:IbA32BtPiV9FU:507:100:Greg Gibson:/home/doghouse/faculty/ggibson:/bin/tcsh

baliane:Ear0NX5lOCJf6:508:100:Bouzid Aliane:/home/doghouse/faculty/baliane:/bin/tcsh

Explanation / Answer

import pwd, grp for p in pwd.getpwall(): print p[0], grp.getgrgid(p[3])[0]

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote